Python Forum
How to add user input together then print the result
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to add user input together then print the result
#1
Hi there this will be my first post so I apologize if my formatting is incorrect, I am still learning python :)

My program asks for how many birthday gifts then takes that number and asks for names based on what number the user inputs eg: 3 then asks for 3 names

Then it takes the length of each name, multiplies that by 10 then that becomes the gift budget. eg: Jack has 4 letters so jack's budget will be $40

Basically what I am stuck on is how do add the total of all names budgets together then print it.

Here is my code.

   
 
 
mylist = []
gift = int(input("How many birthday gifts do you need to buy?"))
for number in range(gift):
   names = input("Enter a name:")
    mylist.append(names)
print(mylist)
for names in mylist: print ("The budget for",names,"'s gift is $",len (names)*10)
And my output looks like this.
Output:
How many birthday gifts do you need to buy?3 Enter a name:Jack Enter a name:John Enter a name:Miller ['Jack', 'John', 'Miller'] The budget for Jack 's gift is $ 40 The budget for John 's gift is $ 40 The budget for Miller 's gift is $ 60 Process finished with exit code 0
  
So it is really just the budget of gifts I am wanting to add together in something like
 
 
print("The total budget for gifts is "....")
Any help would be much appreciated as I've been stuck on this for quite some time now :)
Reply


Messages In This Thread
How to add user input together then print the result - by Liwuid_Ocelot - Mar-22-2017, 01:17 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question Simulate an answer based on user input [Beginner needs guidance] Bombardini 1 1,288 Nov-12-2022, 03:47 AM
Last Post: deanhystad
Bug How to print only vowels from an input? PP9044 8 7,562 Feb-26-2021, 04:02 PM
Last Post: Serafim
  Print user input into triangle djtjhokie 1 2,384 Nov-07-2020, 07:01 PM
Last Post: buran
  Changing Directory based on user input paulmerton4pope 13 8,050 Aug-14-2020, 11:48 AM
Last Post: GOTO10
  how to add the user input from file into list wilson20 8 4,335 May-03-2020, 10:52 PM
Last Post: Larz60+
  How to print the docstring(documentation string) of the input function ? Kishore_Bill 1 3,553 Feb-27-2020, 09:22 AM
Last Post: buran
  Writing a function that changes its answer based on user input SirRavenclaw 2 2,816 Dec-21-2019, 09:46 PM
Last Post: Clunk_Head
  Print the longest str from user input edwdas 5 4,162 Nov-04-2019, 02:02 PM
Last Post: perfringo
  how to add user input to a dictionary to a graph KINGLEBRON 3 3,043 Jul-31-2019, 09:09 PM
Last Post: SheeppOSU
  New to Python - tiny coding assistance on user input function and assign to variable Mountain_Duck 1 2,515 Mar-23-2019, 06:54 PM
Last Post: Yoriz

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020