Python Forum

Full Version: Help with loop & user input
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Quote:now how i can loop through the input value?
It's soon Christmas ,so this should help Wink 
def hm_cars(user_input):
    income = []
    if user_input <= 0:
        return
    for number in range(1, user_input+1):
        income.append(int(input('Income car:{}'.format(number))))
    return income

user_input = int(input('How many cars do you have? '))
cars = hm_cars(user_input)
print(cars)
print('Sum of all cars income {}'.format(sum(cars)))
thanks snippsat !!
This is absolutely what i was looking for.

Have a happy Christmas everyone !
& a peaceful new year.

how can i mark this as solved ?? or
close/mark the thread as done?
Pages: 1 2