python Can someone help with unexpected unindent Python?
Go to solution
Solved by RockSolid1106,
Would be great if you could post the error here. It tells the line on which the error was found, and that is helpful.
Anyways, I found some errors in the code, which I've fixed. Also added comments to help you understand.
Posting some compare screenshots to help you understand better.
Corrected code:
Spoiler
import time import requests def get_random_quote(): try: response = requests.get("https://quote-garden.herokuapp.com/api/v3/quotes/random") if response.status_code == 200: json_data = response.json() data = json_data['data'] except: #missing except statement here, added. pass print("Tere!") time.sleep(3.5) print("Ma olen teie vrtuaalne assistent.") nimi = str(input("Mis on teie nimi?")) print(("Tere, ") + nimi) vanus = str(input("Kui vana te oled?")) print(nimi + (", teie vanus on ") + vanus + ".") hinne1 = input(nimi + (", mis on teie esimene hinne?")) hinne2 = input(nimi + (", mis on teie teine hinne?")) hinne3 = input(nimi + (", mis on teie kolmas hinne?")) vastus = ((int(hinne1) + int(hinne2) + int(hinne3))/3) print(nimi + " sinu vastatud tulemuste järgi, sinu keskmine hinne on " + str(vastus)) if vastus >= 4: time.sleep(3) print("timm") else: time.sleep(2) print("jamps") if vastus > 5: time.sleep(3) print("kuid oled häkker!") time.sleep(2) print(("Sinu andmed on: ") + nimi + (", oled ") + vanus + (" vana ja sinu hinnete keskmine on ") + str(vastus) + (".")) time.sleep(2) kas_õige = input("Kas teie sisestatud andmed on kõik õiged?") if kas_õige == str("jah"): print("Hästi, te olete sisestanud kõik teie andmed õigesti!") else: print("Kahju, kuid oli hea teiega kohuda!") tsitaat = input("Kas te tahate saada suvalist tsitaati?") try: #You can't use except without try. if tsitaat == str("jah"): print(data[0]['quoteText']) else: #the else and except statements were indented for some reason, which I have fixed. print("Tuli viga tsitaadi saamisel!") # except: # print("Midagi läks valesti! Proovi uuesti!")# #also removed the else -> while true continue loop, which prevented the code from executing further. vastus_lõpp = None while answer not in ("jah", "ei"): answer = input("Kas te tahate vestlust lõpetada?") if answer == "jah": #missing code? print("Missing code here") elif answer == "ei": break else: print("Palun sisestage, kas ei või jah.") #Programmi lõpp time.sleep(3.5) while True: print("Näeme varsti!") time.sleep(1.5) print(("Head aega, ") + nimi + ("!")) time.sleep(2) break
Hope this helps. I'm not sure if this executes, because I don't have the appropriate packages, and the language, which I can't understand.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now