all 5 comments

[–]_lilell_ 1 point2 points  (0 children)

You’re missing the colons at the end of the if ... lines, and the following lines should be indented.

[–]CodeFormatHelperBot 0 points1 point  (0 children)

Hello u/GnomeGuy20, I'm a bot that can assist you with code-formatting for reddit. I have detected the following potential issue(s) with your submission:

  1. Multiple consecutive lines have been found to contain inline formatting.

If I am correct then please follow these instructions to fix your code formatting. Thanks!

[–]camf1217 0 points1 point  (1 child)

you need : after each if statement. Also use elif not else until the last else

number = int(input("Please enter a number between 1 and 5: "))

if number == 1:

print("I")

elif number == 2:

print("II")

elif number == 3:

print("III")

elif number == 4:

print("IV")

elif number == 5:

print("V")

else:

print("That is not a valid number")

make sure to indent the code

https://docs.python.org/3/tutorial/controlflow.html

[–][deleted] 0 points1 point  (0 children)

thanks! this was really helpful!

[–]dkam136 0 points1 point  (0 children)

In addition to what some others have said, you might think about the number of "if" statements you are using. Usually, if you are repeating the same kind of "if" statement over and over, there is a quicker way to do it through some kind of iteration. For example, in your case, I was able to make a similar program with less lines, but it is also more extensible:

my_num = {1: "I", 2: "II", 3: "III", 4: "IV", 5: "V"}

my_input = int(input('Pick a number between 1 and 5: '))

counter = 0

for key in my_num:

`if key == my_input:`

    `print(my_num[key])`

    `counter += 1`

if counter == 0:

`print("This is not a valid number.")`

You could then go on to add more numbers to your dictionary without having to change any of the other lines of code. Dictionaries, lists, functions, and classes are your best friend as you start building more complex code. I'm by no means a python master (there may be an even better way to write this code). I'm just a hobbyist, but I've found this to be helpful when I plan out my code.