Skip to content
Sign upLog in
← Back to Community

Detect for numbers and multiple lines

Profile icon
AlfiePython

Is there a way to make code that detects if a number / letter is pressed like,

print("1 - Eat a cookie")
print("2 - Dont eat cookie")

and when the user presses 1 and then enter it will trigger a big of code that is print("You have ate a cookie")

Is there also a way to make the code be in whole print but on separate lines like,

print("1 - Eat a cookie 2 - Dont eat a cookie")
and it will appear as

1 - Eat a cookie
2- Dont eat a cookie

Voters
Profile icon
AlfiePython
Comments
hotnewtop
Profile icon
[deleted]

here ya go
1 = print("Eat a cookie")
2 = print("Dont Eat")
answer = input("type here")
if answer == 1:
print("You have ate a cookie")
if answer == 2:
print("You have chosen not to eat a cookie")

Profile icon
[deleted]

@idrgplayer
mark this correct if it helps.

Profile icon
[deleted]

@idrgplayer
wait i will give you an example.

Profile icon
[deleted]
Profile icon
AlfiePython

The example isnt working it just ends the code

Profile icon
AlfiePython

no tysm for the help lol Im new to coding and still learning a lot and this is rlly helpful

Profile icon
AlfiePython

ty

Profile icon
[deleted]