我有以下脚本:提示输入功能,包括变量
#! /usr/bin/python3
name1 = input('Enter the name of first person ')
name2 = input('Enter the name of second person ')
age1 = int(input("Enter the first age "))
age2 = int(input('Enter the second age '))
print('%s' %name1, 'is %d' %age1, 'years and %s' %name2, 'is %d' %age2, 'years')
agex = age1
age1 = age2
age2 = agex
print('Now we swap ages: %s' %name1, 'is %d' %age1, 'years and %s' %name2, 'is %d' %age2, 'years')
我会想是询问年龄,包括进入名称问题的名字,我的意思是,是这样的:
age1 = int(input("Enter the age of", name1))
但是,这并不工作...
所以,如果你回答,因为第一personame约翰,所以你应该得到:
输入John的年龄:
我怎样才能做到这一点?
请你的问题是一致......你的变量是'name1',但你再谈论'nom1'。 – donkopotamus
您是否尝试使用'+'代替'','? – TigerhawkT3
或者你已经知道的'%'格式。 – TigerhawkT3