Loops - Assignments
1.Try to Write your name 10 times with the help of while loop.
2.Print a simple multiplication table of number given by user input.
3. Do you know Factorial ? It is the product of an integer and all the integers below it; e.g. factorial four (
4!
) is equal to 24. Take a number from user and calculate factorial of a number.
Enter the number : 4
Factorial : 24
4.Take 10 values from user and find out the sum and multiplication and average of the numbers.
5.Create a game 'Guess the number' Game. Let us go through Rules one by one.
1.Computer will generate a Random Number.
2.Ask user to guess the number in 10 chances.
3.If user guesses it right , Score him accordingly like if user guesses in first chance score is 100 , in second chance score should be 90 and so on.
4.If guess number is greater than random number give him 'Hint : Choose a Lower Number' or less than random number give him 'hint : Choose a Higher Number' or if guess number is equal to random , No need to hint , just display score and end the game.
5.Also show how many chances are left.
6.if user could not guess the number, disclose the random number and end the game.
Guess the number : 60
Hint : Choose a Lower Number
---------------Number of Chances Left -------------->1
Guess the number : 50
Hint : Choose a Higher Number.
---------------Number of Chances Left -------------->2
Guess the number : 55
Hint : Choose a Higher Number.
---------------Number of Chances Left -------------->3
Guess the number : 58
You Won .
Score : 70
6.Find all prime numbers between 1 to 2000.
7.Take a number from user and return sum of all digits of the number.
Enter The Number : 484
Sum of the digits : 16
8.Take integer inputs from user until he/she presses q ( Ask to press q to quit after every integer input ). Print average and product of all numbers.
Enter the number : 5
do you want to quit ? no
Enter the number : 10
do you want to quit ? no
Enter the number : 25
do you want to quit ? yes
Sum is 40
Product is 1250
Last updated