Python U1
Python U1
2. Write a program that asks the user for a positive integer value. The program should
calculate the sum of all the integers from 1 up to the number entered. For example, if
the user enters 20, the loop will find the sum of 1, 2, 3, 4, ... 20.
3. Write a program that prompts the user to input a number and prints its
mulitiplication table.
4. Write a program that prompts the user to input a number and prints its factorial. The
factorial of an integer n is defined as n! = 1 x 2 x 3 x ... x n; if n > 0 = 1; if n = 0 For
instance, 6! can be calculated as 1 x 2 x 3 x 4 x 5 x 6.
5. Two numbers are entered through the keyboard. Write a program to find the value of
one number raised to the power of another.
6. Write a program that prompts the user to input a number and reverse its digits. For
example, the reverse of 12345 is 54321; reverse of 5600 is 65.
7. Write a program that asks the user to input a positive integer. Your program should
find and display the sum of digits of number. For example, sum of digits of number
32518 is 3+2+5+1+8 = 19
8. Write a function in python to read the content from a text file "poem.txt" line by line
and display the same on screen.
9. Write a function in python to count the number of lines from a text file "story.txt"
which is not starting with an alphabet "T".
Example: If the file "story.txt" contains the following lines: A boy is playing there.
There is a playground.
An aeroplane is in the sky.
The sky is pink.
Alphabets and numbers are allowed in the password.
10. Write a function in Python to count and display the total number of words in a text
file. Solution