0

Hi, there! I'm pretty new to the programing world and I have a question.

How can I write this code so it returns to surv1.set_sex = raw_input? after the "not in sex statement"?

It's really confusing maybe I should try and write it in someother way?

I don't quite understand the while: try: catch thing... And no of my fellow students can help me around this clock and hour.

I'm counting on you. The internet such a wonderful place! :)

Cheers!

def sex():
    
    surv1.set_sex = raw_input("Välj kön: ")
    sex = ["m","k","b"]
    while surv1.set_sex not in sex:
        print "\nAnge ett giltigt värde m (man) / k (kvinna) / b (både man och kvinna) "
        break
2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by goisagi
0

Could you rephrase that? I'm not sure if this is what you're after, but:

while True:
    surv1.set_sex = raw_input("What's your gender?")
    if surv1.set_sex in ["m","f","n"]
        break
    else
        print "Please answer m (male), f (female), or n (neither)."
0

Thnx alot, you were spot on I will try it! Sorry that I didn't rephrase it to english (original is in swedish)! I'm very grateful! I will try it at once!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.