0% found this document useful (0 votes)
2 views2 pages

Python Practical Questions

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

Python Practical Questions

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Python Practical Questions

1. Converting String to Integer


Write a Python program that asks the user to enter their age as a string. Convert it into an
integer and display the age after adding 5 years.

Example:
Input: "16"
Output: 21

2. Converting Integer to String


Write a program that stores a number in an integer variable and converts it into a string.
Concatenate it with the text " marks" and display the output.

Example:
Output: 85 marks

3. Finding the Length of a String


Write a Python program that asks the user to enter their school name and displays the total
number of characters in it.

Example:
Input: "Royal College"
Output: 13

4. Convert Text to Uppercase


Write a program that asks the user to enter a sentence and converts the entire sentence into
uppercase letters.

Example:
Input: hello world
Output: HELLO WORLD

5. Convert Text to Lowercase


Write a Python program that asks the user to enter their name in capital letters and converts it
into lowercase letters.

Example:
Input: THAMALIE
Output: thamalie

6. Count the Number of Times a Character Appears


Write a program that asks the user to enter a word and a character. Display how many times the
character appears in the word.

Example:
Input word: banana
Input character: a
Output: 3

7. Using Escape Characters


Write a Python program to display the following output using escape characters.

Output:
My name is "Kamal"
I live in Colombo.

8. String Slicing
Write a program that asks the user to enter a word and displays:
- The first 3 characters
- The last 2 characters
- The word in reverse order

Example:
Input: computer
First 3 letters: com
Last 2 letters: er
Reverse: retupmoc

Challenge Question
Write a program that:
1. Inputs a sentence
2. Converts it to uppercase
3. Displays the length of the sentence
4. Displays the first 5 characters using string slicing

9. IF Statement
Write a Python program to take marks from the user and print:
Pass if marks are 40 or above
Fail if marks are below 40

10. WHILE Statement


Write a Python program to print even numbers between 1 and 20 using a while loop.

11. FOR Statement


Write a Python program to print HELLO WORLD 10 times using a for loop.

You might also like