Exercise

  1. Write a program to print out even numbers from 20 to 30

  2. A palindrome is a word which reads the same backward as forward. E.g, 'madam' is a palindrome. Write a program to find if the string given from input is a palindrome or not. Put your code in a continuous loop so the user can input as many words as he or she wishes. If the user keys in 'quit' then the program should stop

  3. Write a program to collect a set of numbers from the user using input and calculate the running Average of all numbers given at any instant of time. Also find the maximum value and minimum value among the numbers. User enters 'quit' to stop the calculation. Ensure that no Errors are thrown when the user does not input the expected values. Handle it gracefully by letting user know what went wrong and what the user is supposed to enter. Display the calculated values with a maximum of 2 decimal places.

  4. Write a guessing game. When the program starts, it picks a number in random between 20-50 and keeps it in memory and asks the user to guess a number. The user inputs a number between 20 and 50, both numbers inclusive. Ensure exceptions are handled gracefully. The system will print out the following hints to help the user win:

    • If the number the user input is below the number in memory by more than 10 then, print out "Your guess is too low. Try again."
    • If the number the user input is below the number in memory by equal to or less than 10 then, print out "Your guess is low. Try again."
    • If the number the user input is above the number in memory by more than 10 then, print out "Your guess is too high. Try again."
    • If the number the user input is above the number in memory by equal to or less than 10 then, print out "Your guess is high. Try again."

Once the user guesses the correct number, then print out "Congratulations, you guessed it right in " + the number of the times the user took to guess the number correctly.

results matching ""

    No results matching ""