+ 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
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")
0
use quit() instead of break
0
ââ
Barryđ§ is there another way to write this easier?
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