Problem mit einem Programm

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • Problem mit einem Programm

    Hi Leute ich bin neu.

    Könnt ihr mir vll bei meinem Problem helfen und sagn was ich falsch mache ?

    Quellcode

    1. # -*- coding: utf-8 -*-
    2. def frage():
    3. vorname = raw_input('Wie heisst du? ')
    4. wow = raw_input('Spielst du World of Warcraft? ')
    5. if (wow == 'Ja'):
    6. sucht = raw_input('Bist du suechtig? ')
    7. if (sucht == 'Ja'):
    8. print ' ' *3 +'#'*1
    9. print ' ' *3 +'#'*1
    10. print '#'*7
    11. print ' ' *3 +'#'*1
    12. print ' ' *3 +'#'*1
    13. print ' ' *3 +'#'*1
    14. print vorname + ', der World of Warcraft Gott sei mit dir.'
    15. else:
    16. sicher = raw_input('Bist du dir ganz sicher? ')
    17. if (sicher == 'Ja'):
    18. sicher2 = raw_input('Bist du dir wirklich ganz sicher das du nicht suechtig bist? ')
    19. if (sicher2 == 'Ja'):
    20. sicher3 = raw_input('Du willst auch keinen 50/50 Joker nehmen? ')
    21. if (sicher3 == 'Nein'):
    22. sicher4 = raw_input('Ey gibs doch zu ich bin auch suechtig. ')
    23. if (sicher4 == 'Nein'):
    24. sicher5 = raw_input('Bist du wirklich nicht suechtig? ')
    25. if (sicher5 == 'Nein'):
    26. print'Gibs doch zu sonst geht das hier noch ewig weiter! '
    27. sicher6 = raw_input('So jetzt nochmal. Bist du suechtig? ')
    28. if (sicher6 == 'Ja'):
    29. print ' ' *3 +'#'*1
    30. print ' ' *3 +'#'*1
    31. print '#'*7
    32. print ' ' *3 +'#'*1
    33. print ' ' *3 +'#'*1
    34. print ' ' *3 +'#'*1
    35. print vorname + ', der World of Warcraft Gott sei mit dir.'
    36. else:
    37. print 'Ach verdammt geh doch kacken du Noob! '
    38. if (wow == 'Nein'):
    39. anfangen = raw_input('Willst du anfangen? ')
    40. if (anfangen == 'Ja'):
    41. print ' ' *3 +'#'*1
    42. print ' ' *3 +'#'*1
    43. print '#'*7
    44. print ' ' *3 +'#'*1
    45. print ' ' *3 +'#'*1
    46. print ' ' *3 +'#'*1
    47. print vorname + ', der World of Warcraft Gott sei mit dir.'
    48. else:
    49. print 'Ach verdammt geh doch kacken du Noob! '
    50. frage()
    Alles anzeigen
  • Re: Problem mit einem Programm

    "Keymaster" schrieb:

    Und wie geht das hier im Forum in so nen Kasten setzen ?

    Einfach Code markieren und dann rechts über dem EIngabefeld SyntaxHighlighting > Programmiersprache auswählen.

    @Problem:
    Komische Sonderzeichen verwendest du.
    Einfach in Zeile1 die utf8 Kodierung erzwingen.

    Quellcode

    1. # -*- coding: utf-8 -*-
  • Ok danke schonmal.

    Aber da ist immer noch etwas was nicht funktioniert.

    Sobal die Frage 'Spielst du World of Warcraft?' auftaucht und man 'Nein' eingibt wirft er eine Fehlermeldung aus:

    Traceback (most recent call last):
    File "C:\Python25\Test.py", line 61, in <module>
    frage()
    File "C:\Python25\Test.py", line 7, in frage
    if (sucht == 'Ja'):
    UnboundLocalError: local variable 'sucht' referenced before assignment

    Und da ich neu bin bitte nicht so ne Fachsprache :D

    P.S.:
    Habe alle Sonderzeichen geändert
  • Vermutlich wolltest du folgendes:

    Quellcode

    1. # -*- coding: utf-8 -*-
    2. def print_msg(vorname):
    3. print ' ' *3 +'#'*1
    4. print ' ' *3 +'#'*1
    5. print '#'*7
    6. print ' ' *3 +'#'*1
    7. print ' ' *3 +'#'*1
    8. print ' ' *3 +'#'*1
    9. print vorname + ', der World of Warcraft Gott sei mit dir.'
    10. def frage():
    11. vorname = raw_input('Wie heisst du? ')
    12. if ('Ja'==raw_input('Spielst du World of Warcraft? ')):
    13. if ('Ja'==raw_input('Bist du suechtig? ')):
    14. print_msg(vorname)
    15. else:
    16. if ('Ja'==raw_input('Bist du dir ganz sicher? ')):
    17. if ('Ja'==raw_input('Bist du dir wirklich ganz sicher das du nicht suechtig bist? ')):
    18. if ('Nein'==raw_input('Du willst auch keinen 50/50 Joker nehmen? ')):
    19. if ('Nein'==raw_input('Ey gibs doch zu ich bin auch suechtig. ')):
    20. if ('Nein'==raw_input('Bist du wirklich nicht suechtig? ')):
    21. print'Gibs doch zu sonst geht das hier noch ewig weiter! '
    22. if ('Ja'==raw_input('So jetzt nochmal. Bist du suechtig? ')):
    23. print_msg(vorname)
    24. else:
    25. print 'Ach verdammt geh doch kacken du Noob! '
    26. else:
    27. if ('Ja'==raw_input('Willst du anfangen? ')):
    28. print_msg(vorname)
    29. else:
    30. print 'Ach verdammt geh doch kacken du Noob! '
    31. frage()
    Alles anzeigen
  • Statt

    Quellcode

    1. wow = raw_input('Spielst du World of Warcraft? ')
    2. if (wow == 'Ja'):
    3. sucht = raw_input('Bist du suechtig? ')
    4. if (sucht == 'Ja'):
    5. print ' ' *3 +'#'*1


    hättest du folgendes schreiben müssen:

    Quellcode

    1. wow = raw_input('Spielst du World of Warcraft? ')
    2. if (wow == 'Ja'):
    3. sucht = raw_input('Bist du suechtig? ')
    4. if (sucht == 'Ja'):
    5. print ' ' *3 +'#'*1


    Das zweite IF soll durch das erste bedingt sein. Dein Code führt zunächst das erste IF und danach unbedingt das zweite aus. Diesen Fehler hast du mehrfach gemacht. Die anderen Änderungen in meinem Code sind eigentlich nur Optimierungen um ihn übersichtlicher zu machen.