Exercises
Exercises
1. Write a program that takes input a number from user & state whether the number is positive,
negative or zero.
2. Write a program that takes a character (i.e. string of length 1) and returns true if it is a vowel,
false otherwise.
3. . Write a program that a) Store correct password in a variable. b) Asks user to enter his/her
password c) Validate the two passwords
i. Check if user has entered password. If not, then give message " Please enter your
password"
ii. Check if both passwords are same. If they are same, show message "Correct! The
password you entered matches the original password".
iii. Show "Incorrect password" otherwise.
4. Rock Paper Scissors Game. Make a two-player Rock-Paper-Scissors game.
(Hint: Ask for player plays (using input), compare them, print out a message of congratulations
to the winner, and ask if the players want to start a new game)
5. Write a program to print multiplication table of any number using for loop. Table number &
length should be taken as an input from user.
Output:
2*1=2
2*2=4
2*3=6
2*4=8
………...
6. Find the sum of factorial from user input and display final result by following the output below:
User input n = 5
Output: 1! + 2! + 3! + 4! + 5! = 120
7. Write a Python program to solve quadratic equation. Assume that Delta > 0.
8. The even/odd reporter Write a for loop that will iterate from 1 to 20. For each iteration, it will
check if the current number is even or odd, and report that to the screen (e.g. "2 is even").
Output:
1 is Odd
2 is Even
3 is Odd
4 is Even
5 is Odd
6 is Even
9. Write a program that will write out a wedge of stars. The user will enter the initial number of
stars, and the program will write out lines of stars where each line has one few star than the
previous line.
User Input n = 4
****
***
**
*
10. Reverse the given sentence from user. Example: word=”Hello” => “olleH”.
11. Write a program that check if a word is a Palindrome or not.
Hint: A palindrome word reads the same forward and backward
12. Write a Python program to find maximum between three numbers.
13. Among the positive natural numbers other than 1, a number that is not prime is called a composite
number. Print the prime and composite numbers from 2-21 as follows.
Coding guideline: use the for statement to solve this problem (nested loop).
14. An Amstrong number is a three-digit integer that is equal to the sum of cubes of each digit. Write
a Python Program that check the Amstrong number from user.
15. An Amstrong number is a three-digit integer that is equal to the sum of cubes of each digit. Find
all Amstrong number among three-digit integers (100-999) and print them as follows.