Jump to content

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.

Spoiler

image.thumb.png.a7231e4957567e4ee8782f41e4827e87.png

image.thumb.png.95f5bf6437446e3c83db468522088fc0.png

 

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.

 

<

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']


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?")
if tsitaat == str("jah"):
    print(data[0]['quoteText'])
        else:
            print("Tuli viga tsitaadi saamisel!")
        except:
            print("Midagi läks valesti! Proovi uuesti!")
else:
    while True:
        continue

vastus_lõpp = None 
while answer not in ("jah", "ei"): 
    answer = input("Kas te tahate vestlust lõpetada?") 
    if answer == "jah": 
          
 
    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

>

 

Link to comment
Share on other sites

Link to post
Share on other sites

Tere! I'm not a python developer, but checking syntax, it looks like an issue arises when you check for an affirmative answer ("jah") and do nothing with it.  Python syntax appears to expect something there.  Though, that may have been edited out.  Not sure.

Link to comment
Share on other sites

Link to post
Share on other sites

41 minutes ago, GroovyFN said:

 

    if answer == "jah": 
	continue
    elif answer == "ei": 
        break 
    else: 
        print("Palun sisestage, kas ei või jah.") 

 

Looks like you need to also be really careful with your indentation with Python.  Which, as I recall, is why I don't use it.  Sometimes I'm a bit careless with indentation, and figuring out those errors is incredibly frustrating.

Link to comment
Share on other sites

Link to post
Share on other sites

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.

Spoiler

image.thumb.png.a7231e4957567e4ee8782f41e4827e87.png

image.thumb.png.95f5bf6437446e3c83db468522088fc0.png

 

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.

 

On 4/5/2024 at 10:13 PM, LAwLz said:

I am getting pretty fucking sick and tired of the "watch something else" responses. It's such a cop out answer because you could say that about basically anything, and it doesn't address the actual complaints. People use it as some kind of card they pull when they can't actually respond to the criticism raised but they still feel like they need to defend some company/person. If you don't like this thread then stop reading it. See how stupid it is? It's basically like telling someone "shut the fuck up". It's not a clever responsive, it doesn't address anything said, and it is rude. 

 ^

 

bruh switch to dark mode its at the bottom of this page

VPN Server Guide

Link to comment
Share on other sites

Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×