Answered step by step
Verified Expert Solution
Question
1 Approved Answer
please write it in python program, better to have the picture of the code.Thank you very much. Material covered while loops Exercises Error checking Read
please write it in python program, better to have the picture of the code.Thank you very much.
Material covered while loops Exercises Error checking Read in the file marks.txt. The file format is one number per line. Your program should iterate over all of these numbers, and test to sec they they are valid numbers. Create two lists: one for valid numbers, one for ivalid numbers. For a number to be valid, the number: Must not have any letters inside of it (it must be numeric usc the string function .isnumeric0 Must be greater than or equal to 0 Must be less than or cual to 100 For output, your program should print out the average of the valid inputs, and the list of invalid numbers along with their line number and a reason why they are invalid. Sample output for data.txt Average of good data: 45.5 Bad data Value 4824" on line 2 is bad because 'too bip Value 'jrfymhn1kt' on line 3 is bad because 'not numeric Value 'kvryvqoddj' on line 4 is bad because 'not numeric Value-95 on 1ine 6 is bad because 'not numeric Hint: Use a tuple to represent cases of invalid data. You can build a tuple using parenthesis: bad- (1, "shdj", "not numeric") # a tuple! Hint 2: You can get line numbes by using the enumerate function Deduction Game Write a game where a user has to guess a number from 1-99 Your program will generate a random number once (pick a number), and will then prompts the user to repeatedly guess the number until they get it correct. During the game, your program will test the number that the user entered compared to the number it picked. If the number that the user guessed is greater than the random number tell the user your guess is too low". If the number that the user guessed is higher than the random mumber, tell the user, "your guess is too high". Let the user continue guessing the number generated until they guess it right. Once the user has successfully guessed the number, tell the user they win, and tell them how many guesses it took them to guess it right. Use a loop to check your user input. Use string's isnumeric should not crash if the user gives you bad input. to check to see if the user has provided you with a valid number before you use a cast to an integer. Your program To create a random number use: import random myRandomNumber - random.randint (1, 99) Sample game: I've picked a number betheen 1 and 99, can you guess it? 58 Nope, it's not 58 Your guess is too low I've picked a number between 1 and 99, can you guess it? 99 Nope, it's not 99 Your guess is too high I've picked a number between 1 and 99, can you guess it? 42 Nope, it's not 42 Your guess is too low I've picked a number between 1 and 99, can you guess it? 93 Nope, it's not 93 Your guess is too high I've picked a number betheen 1 and 99, can you guess it? 83 You got it! It took you 5 guessesStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started