November 15, 2018
Write a program that asks the user to enter a positive integer, and then uses a for
loop to compute the sum of all the integers between 1 and the integer given by the user. For instance, if the user enters 5, your program should display 15 at the screen (i.e., 1 + 2 + 3 + 4 + 5 = 15).
Then, answer the following questions:
while
loop?You can modify your program to check your answers to the previous questions. Once you are done, modify your original program with two respects:
We will revisit our guessing game from Lab 16. If you haven’t solved it already, have a look back and solve it.
Read carefully the challenge below, and think about the parts of your previous program you can re-use to solve this one.
Write a program that asks the user which level of difficulty (s)he wants to play: easy, medium or hard. Then, generate a random number: between 0 and 10 for easy, between 0 and 50 for medium, and between 0 and 100 for hard. Then, let the user try to guess the number you randomly generated:
- if the number given by the user is less than the random number generated, your program should display a message saying that the user should try with a greater value,
- if the number given by the user is greater than the random number generated, your program should display a message saying that the user should try with a lesser value,
- and if the number given by the user is the same as the random number generated, your program should display a message saying that the user won, and how many attempts it took him/her to guess correctly.