CMSC 201 |
Lab 4: LoopsRemember, before running each program type: scl enable python33 bash ProgramsCalculate the average! To practice using while loops, we are going to make a program where the user enters how many numbers they would like to take the average of, the numbers they would like to average, and prints out the average to the user. Steps to complete this program:
**This program should only have two input statements, and should work no matter how many values the user wants to average** The Guessing Game! In this program, you will be given code that generates a random number between 1 and 10 (inclusive). Your job is to write code that adds on to it, prompting the user to enter a guess repeatedly until they no longer want to play. Sample output code: Guess a number between 1 and 10 (inclusive) and I'll tell you if you're right! Enter your guess: 2 NOPE. Would you like to guess again? (y,n) y Enter your guess: 3 NOPE. Would you like to guess again? (y,n) y Enter your guess: 5 NOPE. Would you like to guess again? (y,n) y Enter your guess: 7 YOU WIN!!!!!!! or Guess a number between 1 and 10 (inclusive) and I'll tell you if you're right! Enter your guess: 3 NOPE. Would you like to guess again? (y,n) y Enter your guess: 6 NOPE. Would you like to guess again? (y,n) y Enter your guess: 2 NOPE. Would you like to guess again? (y,n) n Steps to complete this program:
Provided code: import random randnum = random.randint(1,10) print("Guess a number between 1 and 10 (inclusive) and I'll tell you if you're right!") |