python) Please locate and identify at least 10 problems in the following code. Explain how to fix them or why they are an error. Use the line numbers in your answers. 1. import random 2. n = 20 3. to_be_guessed = str(n * random.random()) + 1 4. guess == 0 5. whileLoop guess != to_be_guessed: 6. guess = int(input("New number: ')) 7. if guess > 0 8. if guess > to_be_guessed: 9. print(Number too large") 10. elseif guess < to_be_guessed: 11. print("Number too small") 12. else: 13. print("Sorry that you're giving up!" 14. break: 15. notWhile: 16. print("Congratulations. You made it!
Control structures
Control structures are block of statements that analyze the value of variables and determine the flow of execution based on those values. When a program is running, the CPU executes the code line by line. After sometime, the program reaches the point where it has to make a decision on whether it has to go to another part of the code or repeat execution of certain part of the code. These results affect the flow of the program's code and these are called control structures.
Switch Statement
The switch statement is a key feature that is used by the programmers a lot in the world of programming and coding, as well as in information technology in general. The switch statement is a selection control mechanism that allows the variable value to change the order of the individual statements in the software execution via search.
(python)
Please locate and identify at least 10 problems in the following code. Explain how to fix them or why they are an error. Use the line numbers in your answers.
1. import random
2. n = 20
3. to_be_guessed = str(n * random.random()) + 1
4. guess == 0
5. whileLoop guess != to_be_guessed:
6. guess = int(input("New number: '))
7. if guess > 0
8. if guess > to_be_guessed:
9. print(Number too large")
10. elseif guess < to_be_guessed:
11. print("Number too small")
12. else:
13. print("Sorry that you're giving up!"
14. break:
15. notWhile:
16. print("Congratulations. You made it!")
Step by step
Solved in 2 steps