Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Adding Variables
#2
I'm assuming the goal of your program is to add all inputs, to see if you get a total value = 1, if this is the case; All your inputs are of a string datatype and not what they're supposed to be, which is integers, since you're adding them. Lets say the user gives all your variables these values as inputs

E_String = "1"
A_String = "0" 
D_String = "0" 
G_String = "0" 
B_String = "0" 
e_String = "0"
Since input() accepts it as a string, your variable all_string_sum is essentially adding "1" + "0" + "0"...etc to give a combined string of "100000". What you need to do is convert your input to accept user values as integers, which you can do by modifying your code as such:

E_String = int(input('What are you fretting on the low E string? '))
A_String = int(input('What are you fretting on the A string? '))
D_String = int(input('What are you fretting on the D string? '))
G_String = int(input('What are you fretting on the G string? '))
B_String = int(input('What are you fretting on the B string? '))
e_String = int(input('What are you fretting on the high e string? '))
all_string_sum = (E_String + A_String + D_String + G_String + B_String + e_String)
if all_string_sum == 1:
    print ("E")
Good rule of thumb when debugging is to check what your variable holds, by printing it.
Reply


Messages In This Thread
Adding Variables - by absolum - Jul-17-2019, 06:58 PM
RE: Adding Variables - by abi17124 - Jul-17-2019, 07:31 PM
RE: Adding Variables - by jefsummers - Jul-17-2019, 08:15 PM
RE: Adding Variables - by absolum - Jul-18-2019, 12:32 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  File path by adding various variables Mishal0488 2 1,027 Apr-28-2023, 07:17 PM
Last Post: deanhystad
  variables vcnt, ocnt, and mcnt adding previous values and not resetting to 0 archanut 2 1,929 Feb-12-2021, 06:56 PM
Last Post: deanhystad
  adding properties to variables rudihammad 0 1,683 May-06-2020, 05:09 AM
Last Post: rudihammad
  Adding markers to Folium map only adding last element. tantony 0 2,122 Oct-16-2019, 03:28 PM
Last Post: tantony

Forum Jump:

User Panel Messages

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