Python Forum

Full Version: I need simple help with python?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
If someone can send code: I am making simple program which I will use in calculating Pitagora's theorem, so I made that program but I want to python draw that triangle in turtle but I do not to code size of angle?
You use the turn command to turn the turtle. You can pass it an angle in degrees to tell it how far to turn.
Wait I'll send you code, sry it is on Croatian but you'll see
#ka_hip = kateta_druga/hipotenuza
#sin_ka_hip = math.sin(math.radians(ka_hip)) #I need math.sin with exponent(-1)

import math
from turtle import*
odgovor = str(input("Ako želite izračunati stranice jednakokračnog trokuta upišite AAC, a ako želite izračunati stranice raznostraničnog trokuta upišite ABC: "))
odgovor = odgovor.upper()
if odgovor == ("ABC"):
    stranica = str(input("Upišite stranicu koju želite izračunati: "))
    stranica = stranica.capitalize()
    if stranica == ("A"):
        kateta_druga = int(input("Upišite veličinu druge katete: "))
        hipotenuza = int(input("Upišite veličinu hipotenuze: "))
        dulj_stranice = math.sqrt((hipotenuza**2) - (kateta_druga**2))
        str_dulj_stranice=str(dulj_stranice)
        print("Duljina stranice je " + str_dulj_stranice)
        fd(dulj_stranice*100)
        lt(90)
        fd(kateta_druga*100)
        rt(180)
        #ka_hip = kateta_druga/hipotenuza
        #sin_ka_hip = math.sin(math.radians(ka_hip)) #I need math.sin with exponent(-1)
    elif stranica == ("B"):
        kateta_druga = int(input("Upišite veličinu druge katete: "))
        hipotenuza = int(input("Upišite veličinu hipotenuze: "))
        dulj_stranice = math.sqrt((hipotenuza**2) - (kateta_druga**2))
        str_dulj_stranice=str(dulj_stranice)
        print("Duljina stranice je " + str_dulj_stranice)
    elif stranica == ("C"):
        kateta_prva = int(input("Upišite veličinu prve katete: "))
        kateta_druga = int(input("Upišite veličinu druge katete: "))
        dulj_stranice = math.sqrt((kateta_prva**2) + (kateta_druga**2))
        str_dulj_stranice=str(dulj_stranice)
        print("Duljina stranice je " + str_dulj_stranice)
if odgovor == ("AAC"):
    stranica = int(input("Upišite duljinu stranice: "))
    hipotenuza = math.sqrt((stranica**2) + (stranica**2))
    hipotenuza = str(hipotenuza)
    print("Duljina hipotenuze je " + hipotenuza)
    fd(stranica*100)
    lt(90)
    fd(stranica*100)
    rt(180)
    rt(45)
    fd(hipotenuza*100)
Okay, I was wrong about turn, I don't know what I was thinking.

What problem are you getting? I see that you are converting hipotenuza to string on line 35, which makes it an invalid input to fd on line 41. You should remove that, and use string formatting for the print: print('Duljina hipotenuza je {:.2f}'.format(hipotenusa)
No, I need to import turtle and math, how to import both modules, import math,turtle doesn't work
I am not having that problem with your code. Both are standard modules, so there should be no trouble importing them. What is the full text of the error you are getting?
I am not getting error it just doesn't open turtle window
It is opening it for me, although then it is closing it. Maybe this is happening so fast you don't notice. Try adding input('Press enter to finish: ') at the end. Also note that are drawing way too much. Unless you enter really small values, the turtle is going to go off the screen because you are multiplying everything by 100.