Hi undzwar habe ich ein problem ihr kennt doch sicherlich dass buch "Python crash course" nun stecke ich in den buch fest auf seite 127.
Undzwar sollte ich die aufgaben lösen dies hab ich natürlich auch gemacht aber dass problem ist ich verstehe einige fragen nicht da mein englich so gut ist.
undzwar sollte ich die beiden aufgaben lösen :
7- 6. Three Exits:Write different versions of either Exercise 7-4 or Exercise 7-5
that do each of the following at least once:
• Use a conditional test in the whilestatement to stop the loop .
• Use an activevariable to control how long the loop runs .
• Use a breakstatement to exit the loop when the user enters a 'quit'value .
Ist meine antwort bzw. mein code richtig ?
age = 13
if age != 3:
print("You can enter free !")
if age != 12:
print("You must pay 10 $ ")
if age != 13:
print("15 $ ")
Bitte um hilfe wäre echt nett danke im voraus schon mal hab über all nach der lösung gesucht aber nichts gefunden.
Python crash course "While"
wo ist in deinem Code die while Schleife?
wo die active variable?
wo das break statement?
Ich bin Pazifist und greife niemanden an, auch nicht mit Worten.
Für alle meine Code Beispiele gilt: "There is always a better way."
https://projecteuler.net/profile/Brotherluii.png
Für alle meine Code Beispiele gilt: "There is always a better way."
https://projecteuler.net/profile/Brotherluii.png
- __blackjack__
- User
- Beiträge: 13111
- Registriert: Samstag 2. Juni 2018, 10:21
- Wohnort: 127.0.0.1
- Kontaktdaten:
@Fakhro: Mal der Code mit Code-Tags, damit man die Einrückung sehen kann, die bei Python wichtig ist:
Auch ohne Schleife kann man da schon sagen, das der Code nicht sinnvoll/falsch ist. Hast Du den mal ablaufen lassen? Macht die Ausgabe das man umsonst rein kommen kann und $10 bezahlen muss nicht erschreckend wenig Sinn?
Code: Alles auswählen
age = 13
if age != 3:
print("You can enter free !")
if age != 12:
print("You must pay 10 $ ")
if age != 13:
print("15 $ ")
„All religions are the same: religion is basically guilt, with different holidays.” — Cathy Ladman
Ihr habt glaube ich meine frage nicht so ganz verstanden
Hier sind die antworten für die fragen :
7-4. Pizza Toppings: Write a loop that prompts the user to enter a series of
pizza toppings until they enter a 'quit'value .As they enter each topping,
print a message saying you’ll add that topping to their pizza .
7-5. Movie Tickets: A movie theater charges different ticket prices depending on
a person’s age .If a person is under the age of 3, the ticket is free; if they are
between 3 and 12, the ticket is $10; and if they are over age 12, the ticket is
$15 .Write a loop in which you ask users their age, and then tell them the cost
of their movie ticket .
prompt = "\nWhat do you would for toppings in you pizzas ? "
prompt += "\nWhen you're finish please enter 'quit' : "
while True:
toppings = input(prompt)
if toppings != 'quit':
print("I will add the topings " + toppings.title() + " to their pizzas")
else:
break
print("Welcome to the movie theater in los angels !")
prompt = "\nHow old are you ?"
prompt += "\nPlease enter 'quit' when you are finish : "
while True:
age = input(prompt)
if age == 'quit':
break
age = int(age)
if age < 3:
print("For you its free !")
elif age < 13:
print("The cost is 10 $ ")
else:
print("15 $ is the cost !")
Nun meine frage ist Was die frage jetzt hier heißen soll oder gehören die antworten auch zu den fragen ?
7- 6. Three Exits:Write different versions of either Exercise 7-4 or Exercise 7-5
that do each of the following at least once:
• Use a conditional test in the whilestatement to stop the loop .
• Use an activevariable to control how long the loop runs .
• Use a breakstatement to exit the loop when the user enters a 'quit'value .
Hier sind die antworten für die fragen :
7-4. Pizza Toppings: Write a loop that prompts the user to enter a series of
pizza toppings until they enter a 'quit'value .As they enter each topping,
print a message saying you’ll add that topping to their pizza .
7-5. Movie Tickets: A movie theater charges different ticket prices depending on
a person’s age .If a person is under the age of 3, the ticket is free; if they are
between 3 and 12, the ticket is $10; and if they are over age 12, the ticket is
$15 .Write a loop in which you ask users their age, and then tell them the cost
of their movie ticket .
prompt = "\nWhat do you would for toppings in you pizzas ? "
prompt += "\nWhen you're finish please enter 'quit' : "
while True:
toppings = input(prompt)
if toppings != 'quit':
print("I will add the topings " + toppings.title() + " to their pizzas")
else:
break
print("Welcome to the movie theater in los angels !")
prompt = "\nHow old are you ?"
prompt += "\nPlease enter 'quit' when you are finish : "
while True:
age = input(prompt)
if age == 'quit':
break
age = int(age)
if age < 3:
print("For you its free !")
elif age < 13:
print("The cost is 10 $ ")
else:
print("15 $ is the cost !")
Nun meine frage ist Was die frage jetzt hier heißen soll oder gehören die antworten auch zu den fragen ?
7- 6. Three Exits:Write different versions of either Exercise 7-4 or Exercise 7-5
that do each of the following at least once:
• Use a conditional test in the whilestatement to stop the loop .
• Use an activevariable to control how long the loop runs .
• Use a breakstatement to exit the loop when the user enters a 'quit'value .
Hier sind drei Varianten aufgeführt, wie man eine while-Schleife gestalten kann. Du hast jetzt zwei while-Schleifen gezeigt. Welche der drei Varianten hast Du da umgesetzt? Wie würde eine Umsetzung in den zwei anderen Varianten aussehen?
Es ist doch die ein und selbe while schleife nur bei der einen nutzte ich den int um die nachfrage nach zu gehen zum und bei der anderen "While" nutzte ich fast den selben code außer natülich mit ein paar änderungen und ohne die "If" funktionen.
Falls ich falsch liegen sollte bitte ich um aufklärung bin kein profi programmierer.
Wie meinst dass mit " wie würde eine umsetztung in den zwei anderen varianten aussehen "?
Falls ich falsch liegen sollte bitte ich um aufklärung bin kein profi programmierer.
Wie meinst dass mit " wie würde eine umsetztung in den zwei anderen varianten aussehen "?
Beide while-Schleifen verwenden das selbe Konzept. Es bleiben also noch zwei andere Arten übrig.
Beantworte doch erst die Frage, welche Variante Du in Deinen while-Schleifen umgesetzt hast.
1. A conditional test in the while statement to stop the loop .
2. An `active` variable to control how long the loop runs .
oder
3. A break statement to exit the loop when the user enters a 'quit' value .
Beantworte doch erst die Frage, welche Variante Du in Deinen while-Schleifen umgesetzt hast.
1. A conditional test in the while statement to stop the loop .
2. An `active` variable to control how long the loop runs .
oder
3. A break statement to exit the loop when the user enters a 'quit' value .
Ich glaube ich habe es verstanden ...
Undzwar soll ich andere versionen schreiben aus denen ich die ersten geschrieben habe
mit einer "While" schleife und einem konditional test um die schleife zu stoppen kurz und knapp gesagt Eig. fast genau dass selbe aus meinen vorherigen code
lieg ich richtig ?
Undzwar soll ich andere versionen schreiben aus denen ich die ersten geschrieben habe
mit einer "While" schleife und einem konditional test um die schleife zu stoppen kurz und knapp gesagt Eig. fast genau dass selbe aus meinen vorherigen code
lieg ich richtig ?
Danke dir sirius echt nett, für die schnelle antwort.
hab mich die ganze zeit schon gewundert ich meine was mich so irritierthat war dass in meinem code bereits die while schleife mit dem konditional test drinn war und genau so dass break statment ich wusste garnicht was die wollen bis ich mich immer wieder gefragt habe dass bereits alles in meinen code zu finden war außer die achtive while schleife die fehlt noch.
ich danke dir nochmals vielmals
hab mich die ganze zeit schon gewundert ich meine was mich so irritierthat war dass in meinem code bereits die while schleife mit dem konditional test drinn war und genau so dass break statment ich wusste garnicht was die wollen bis ich mich immer wieder gefragt habe dass bereits alles in meinen code zu finden war außer die achtive while schleife die fehlt noch.
ich danke dir nochmals vielmals