简体   繁体   中英

Can you store multiple user input data into single variable - Python 3.6

python noob here. I'm sure this is an easy question.. Is it possible to get numerical data collected from multiple user input questions into a single variable? For example, if I wanted to ask a user three questions:

int(input("What is your yearly income?"))

int(input("What is your partner's yearly income?"))

int(input("Enter any additional income"))

Can you store all of that data collected directly into a single variable named total_income . What I would like is to be able to get a sum total into a single variable.

This might be helpful:

t = 0

t += int(input("What is your yearly income?"))
t += int(input("What is your partner's yearly income?"))
t += int(input("Enter any additional income"))

If your input in a single line(separated by space):

a=sum(map(int,input().split()))
print (a)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM