0
HELP NEW CODE FOR PYTHON
PLEASE SOMEONE SEE WHATS WRONG WITH MY CODE I IN DIRE NEED PLS https://code.sololearn.com/cf83mciz9aff/?ref=app
6 Answers
+ 2
protocol = 4770
virus = 'YOU HAVE BEEN HACKED!!!'
virus_2 = 'NETWORK BREACHED!'
prompt = 'NETWORK IS UNDER ATTACK! ENTER PROTOCOL NUMBER TO BLOCK HACKER!'
players_number = int(input(prompt))
while True:
if players_number < protocol:
print(virus)
break
if players_number > protocol:
print(virus_2)
break
if players_number == protocol:
print("Network Secure")
break
+ 3
# You have many mistakes:
protocol = '4770'
virus = 'YOU HAVE BEEN HACKED!!!'
virus_2 = 'NETWORK BREACHED!'
prompt = 'NETWORK IS UNDER ATTACK! ENTER PROTOCOL NUMBER TO BLOCK HACKER!'
#players_number = input(prompt)
# I supposed that your purpose is to write a kind of guess number game? So, you must put the input inside your infinite loop:
while True:
players_number = input(prompt)
# and to compare numerically strings, you must convert them to number, else you are comparing them alphabetically (ie. '51' > '4770' is True)...
if int(players_number) < int(protocol):
print(virus)
break
if int(players_number) > int(protocol):
print(virus_2)
else:
# technically you need an elif statement (stand for else if) if you provide the below condition... but in this case, it is implicitly always true, so no need to give it here...
# players_number == protocol
# and why doing a loop below for print once?
# and almost, range(1) produce an empty list (ie. zero iteration)... do at least range(2) or better not have none loop at all, as your others print statements :P
# for i in range(1):
# print("Network Secure")
print("Network Secure")
# Anyway, this will ask for 'protocole' infinitly, until user enter a number lesser than 4770 (virus win case): I don't really understand what's the' purpose of your code?
# In addition, in code playground you're required for all input at once, separated by new lines, so you must end it with a value lesser than 'protocol' else you will reach thr code playground time limit ^^
+ 3
Isn't my answer not most accurate than the one marked as 'best answer'? @@
+ 2
For numbers in input u always need to do a casting like int(input("number" )) otherwise python uses it as a String
+ 2
And u forgot to put a break, after print the message, without it u do a infinite loop
0
Thank you so much I'm new to coding and still practicing