# Will This Code Work?

Im Just Like 4 or 5 Months new to Coding And i wanna ask if this code will work or not:

``````time.sleep(0.5)
num1 = int(input("#1 Enter a number between 1 and 45: "))
num2 = int(input("#2: Enter a number between 1 and 45: "))
num3 = int(input("#3: Enter a number between 1 and 45: "))
num4 = int(input("#4: Enter a number between 1 and 45: "))
num5 = int(input("#5: Enter a number between 1 and 45: "))
power = int(input("Power Ball Number: Enter a number value between 1 and 70: "))

time.sleep(1)
print("{:02d} {:02d} {:02d} {:02d} {:02d}\t\t\t{:02d}".format(num1, num2, num3, num4, num5, power))
``````

1 Like

Well sure, it seems to work fine. One thing is that print statement is… unreadable. At least for me, who is very used to fstrings.

1 Like

That code in particular seems to work fine, but I had a quick look at the Repl and it seems like it’s impossible to match any numbers at all.

``````score=1 if gam1==(num1 or num2 or num3 or num4 or num5) else 0
score=score+1 if gam2==(num1 or num2 or num3 or num4 or num5)  else score
score=score+1 if gam3==(num1 or num2 or num3 or num4 or num5)  else score
score=score+1 if gam4==(num1 or num2 or num3 or num4 or num5)  else score
score=score+1 if gam5==(num1 or num2 or num3 or num4 or num5)  else score
``````

The above code isn’t checking if gam* matches any of the numbers. `(num1 or num2 or num3 or num4 or num5)` will always evaluate to `True` because numbers (except zero) are truthy. The “gam” variables are numbers, and therefore can never equal `True`

EDIT: nevermind, that code does work! It seems like python goes against my understanding of code and type casts.

Also, on this line:

``````power_print="and did not get " if gam_power!=True else "and got "
``````

you should be checking `score_power`, not `gam_power`

4 Likes

So It is Worth it?

Because I Added it and i feel like changing it

The only thing you can do, if you want ti change it, is use loops to gather the number and construct the string for the last print.
For the rest it surely works,

2 Likes

Everything will work with this program, except you forgot the `import time` statement. Since you’re in Python, you need to import that library, otherwise the `time.sleep` function will not work.

You can also use a for loop and a list instead of assigning each variable a name. An example of this code would look like this:

``````import time

time.sleep(0.5)
numlist = [0, 0, 0, 0, 0]

for i in range (5):
numlist[i] = int(input("Enter a number between 1 and 45: "))
power = int(input("Power Ball Number: Enter a number value between 1 and 70: "))

time.sleep(1)
print("{:02d} {:02d} {:02d} {:02d} {:02d}\t\t\t{:02d}".format(numlist, numlist, numlist, numlist, numlist, power))
``````
2 Likes

They already did lol, although they did not include it in the snippet, which would be more helpful.

1 Like

Ah, I see. I didn’t see it in the snippet so I assumed it wasn’t in there. Other than that, everything should work lol.

1 Like

Thats All i Need to hear

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.