Strings

This is the place for queries that don't fit in any of the other categories.

Re: Strings

Postby Mekire » Tue Aug 27, 2013 11:35 am

That is not the way your instructor wants you to do the problem. In fact I would really hope that he wouldn't give a passing grade to it. The entire purpose of all the assignments you have shown us so far has been to teach you about loops. Stop trying to avoid it and actually experiment. I don't know the reason you are taking a class in programming, but sincerely, if you don't change your approach to problem solving you re not going to make much progress.

-Mek
User avatar
Mekire
 
Posts: 987
Joined: Thu Feb 07, 2013 11:33 pm
Location: Amakusa, Japan

Re: Strings

Postby el_manu » Tue Aug 27, 2013 1:39 pm

Mekire wrote:That is not the way your instructor wants you to do the problem. In fact I would really hope that he wouldn't give a passing grade to it. The entire purpose of all the assignments you have shown us so far has been to teach you about loops. Stop trying to avoid it and actually experiment. I don't know the reason you are taking a class in programming, but sincerely, if you don't change your approach to problem solving you re not going to make much progress.

-Mek


Our instructor doesn't care how we do the problem. It gets marked in a marking system that checks if our code produces the right output, it doesn't care about the method, but they teach us loops as notes because that is the easiest way. i only started programming last week and i am starting with python. No programming experience before that. i am 15, and yeah i don't have a lot of time on my hands as i am doing other stuff. My friend will want to copy my code and he will want loops so I will need to teach him loops (I am the smartest at this is my tutoring class..i know laugh as much as you want, we are all noobs just starting). at some stage i will have to learn, but for now i don't get what for loops mean so i give up for now.
I am taking the class because I was advised to take it with my friends by my IST teacher at school because we knew nothing.
Mekire wrote:Stop trying to avoid it and actually experiment. -Mek

i don't know WHAT to experiment on.

what do i write. this?? i don't know

Code: Select all
a = input("Music? ")
b = a.upper()
alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
for b in range(alphabet[7], alphabet[25]):
    print("That's not music")
if b not in (alphabet[7], alphabet[25]):
   print("That's music!")
el_manu
 
Posts: 87
Joined: Mon Aug 19, 2013 8:30 am

Re: Strings

Postby Mekire » Tue Aug 27, 2013 2:24 pm

So loop through the word that is input and check if each letter is in the list of accepted music characters.

Code: Select all
MUSIC_LETTERS = "ABCDEFG"
word = input("Please enter some music (A-G): ").upper()

for letter in word:
    if letter not in MUSIC_LETTERS:
        print("Not music.")
        break
else:
    print("Music.")

There is actually a short cut to do this by using the all function.

For example:
Code: Select all
word = input("Please enter some music (A-G): ").upper()
if all(letter in "ABCDEFG" for letter in word):
    print("Music.")
else:
    print("Not music.")

Try to understand what is going on in at least the first one.
-Mek
User avatar
Mekire
 
Posts: 987
Joined: Thu Feb 07, 2013 11:33 pm
Location: Amakusa, Japan

Previous

Return to General Coding Help

Who is online

Users browsing this forum: Baidu [Spider], Google [Bot] and 5 guests