[Tutor] Wrapping my head around global variables!!

bob gailer bgailer at gmail.com
Fri Jan 28 21:12:53 CET 2011


On 1/28/2011 10:22 AM, Nevins Duret wrote:
> Hello Python collective,
>
>         I am trying to wrap my head around what exactly is causing me 
> not to get any output or error message in the following code:

There are so many problems with this program it is hard to know where to 
begin. Have you successfully run any other Python programs?

What operating system are you using?

What do you do to run the program?

Why no output? Simple. Here are the steps the program executes

start
import random
def main():
if __name__ == "__main__":
main()
return chosen_letter
end

Please study the program till you understand what is happening. Then 
figure out what to change.


>
>> #!/usr/bin/env python3.1
>>
>> import random
>>
>> def main():
>>
>>     def chosen_letter():
>>
>>         chosen_letter = Consonant()
>>         chosen_letter = Vowel()
>>
>>     return chosen_letter
>>
>>     Consonant = random.choice( [B, C, D, F, G, H, J, K, L, M, N, P, 
>> Q, R, S, T, V, W, X, Z] )
>>     Vowel = random.choice( [A, E, I, O, U, Y] )
>>     print("Choose a letter"( Consonant, Vowel ))
>>     print("You randomly chose"( Consonant, Vowel ))
>>
>>     if Consonant == ( "B C D F G H J K L M N P Q R S T V W X Z" ):
>>         print("You randomly chose a Consonant")
>>     else:
>>         print("You randomly chose a Vowel")
>>
>>     if Consonant:
>>             gameStatus = "CONTINUE"
>>     elif Vowel == A or Vowel == E or Vowel == I or Vowel == O or 
>> Vowel == U or Vowel == Y:
>>             gameStatus = "FINISHED ALL VOWELS"
>>
>>     if gameStatus == "FINISHED ALL VOWELS":
>>         print("FINISHED DISPLAYING ALL VOWELS")
>>     else:
>>         print("LOOKING FOR MORE VOWELS")
>>
>> if __name__ == "__main__": main()
>>
> All this code is intended to do is to have a user, in this case my 4 
> year old, choose letters of the alphabet until all vowels are 
> specified.  For whatever reason I'm neither getting an error message 
> nor am I obtaining any messages in the output console.  Any help on 
> this would be greatly appreciated.  I eventually want to make this 
> into a gui in order to introduce young kids to programming, by having 
> the letters print out to screen as the user makes choices based on 
> vowels and consonants.  Again, thank you for any help and expertise.
>
> Best Regards,
>
> freesparks
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>


-- 
Bob Gailer
919-636-4239
Chapel Hill NC



More information about the Tutor mailing list