Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Adding Variables
#1
Hello! I am working on a program for guitar. This is a rather simple problem but I am new to coding and don't know why the heck this is not working. I tried two ways, as you can see below. Any help is appreciated. Thanks!
E_String = input('What are you fretting on the low E string? ')
A_String = input('What are you fretting on the A string? ')
D_String = input('What are you fretting on the D string? ')
G_String = input('What are you fretting on the G string? ')
B_String = input('What are you fretting on the B string? ')
e_String = 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")
Method #2

if E_String + A_String + D_String + G_String + B_String + e_String == '1':
    print("D+")
Reply
#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
#3
I play guitar as well. Not sure what you are trying to do here - adding up the finger positions, so a C chord would be 0+3+2+0+1+0=6, an A chord would be 0+0+2+2+2+0 = 6? You throw me by the comparison to the value 1, as there is no 6 string chord that would have that value. Even an Em7 would be 2.

Agree with the above, but in the larger scheme, what are you trying to do?
Reply
#4
(Jul-17-2019, 08:15 PM)jefsummers Wrote: I play guitar as well. Not sure what you are trying to do here - adding up the finger positions, so a C chord would be 0+3+2+0+1+0=6, an A chord would be 0+0+2+2+2+0 = 6? You throw me by the comparison to the value 1, as there is no 6 string chord that would have that value. Even an Em7 would be 2.

Agree with the above, but in the larger scheme, what are you trying to do?

Hey Man!
That was a ruse, but nice to see another player here! Not that it is at all uncommon. While I did actually write out a system that would work using the "fret sum" method, ( Tongue ) it is not at all efficient and does not work in harmony with the previous layer of code I have written.
Thank you!
I teach music :) Hey dude, what about an A Dominant 5 chord? Doesn't have to be all 6 strings to have a sum of one. :)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  File path by adding various variables Mishal0488 2 964 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,885 Feb-12-2021, 06:56 PM
Last Post: deanhystad
  adding properties to variables rudihammad 0 1,659 May-06-2020, 05:09 AM
Last Post: rudihammad
  Adding markers to Folium map only adding last element. tantony 0 2,094 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