比較兩個(gè)名為target的變量,并使用Python 3猜測(cè)一個(gè)是整數(shù),一個(gè)是字符串。import randomimport systarget = random.randint(1, 20)name = input ('Hello, what is your name?')print ('Hello, %s. I am thinking of a number from 1 to 20. You will have 3 tries, and after each try, I will tell you if the number that I am thinking of is lower or higher. Try to guess it!' % name) guess = input ('What number do you think I am thinking of?')if guess == target: print ('Congratulations! You won! Please play again!') sys.exit()else: print ('You did not guess the number correctly.') if target < guess: print ('The number that I am thinking of is smaller than your guess. Try again') else: print ('The number that I am thinking of is larger than your guess. Try again!')
您如何比較2個(gè)變量與不同類型的數(shù)據(jù)?
慕工程0101907
2021-04-08 04:21:34