+ 1

Help Please

hi pls how should i write this ? import string number = input("Please enter ur number:\n") if number == string: print("please enter a number") break else: number = float(number) if (number) < 50: print(f"Your number {number} < 50") if (number) > 50: print(f"Your number {number} > 50") error : line 7 break ^ SyntaxError: 'break' outside loop

2nd Sep 2019, 11:36 AM
Arya
Arya - avatar
4 Answers
+ 2
The break keyword is used in loops. Remove the break keyword Checking if the entered value is string or not won't work that way... Try this 👇 try: number = float(input("Please enter ur number:\n")) if (number) < 50: print(f"Your number {number} < 50") if (number) > 50: print(f"Your number {number} > 50") except ValueError: print("Please enter a number")
2nd Sep 2019, 11:50 AM
Baribor Saturday
Baribor Saturday - avatar
0
use quit() instead of break
2nd Sep 2019, 5:07 PM
Rora
0
✔✅Barry🔧 is there another way to write this easier?
2nd Sep 2019, 8:35 PM
Arya
Arya - avatar
0
If is not a loop statement hence there is no need of break (break is used to get out of loop)  three basic types of control structures: Sequential: default mode. Sequential execution of code statements (one line after another) -- like following a recipe Selection: used for decisions, branching -- choosing between 2 or more alternative paths. In C++, these are the types of selection statements: if if/else switch Repetition: used for looping, i.e. repeating a piece of code multiple times in a row. In C++, there are three types of loops: while do/while for Here is my modified code... Hope it will help you https://code.sololearn.com/crVtXIi3TyJs/?ref=app
3rd Sep 2019, 7:21 AM
Sgk101
Sgk101 - avatar