lundi 3 décembre 2018

unorderable types: str() >= int() with if statement [duplicate]

This question already has an answer here:

Alright so basically I want to make an if statement to check if the user inputted above 18 years old or below like this age = input("enter your age: ") but the problem is happening because of line 8 if age >= legal: I'm getting this message unorderable types: str() >= int()

import random

age = input("Enter your age: ")
legal = 18

def aboveage():
    if age >= legal:
        print("Would you like to play?")
    else:
        print("You can't play")
    return

aboveage()

Edit:

So I fixed it by doing this

if (int(age)) >= (int(legal)):

Aucun commentaire:

Enregistrer un commentaire