Python Forum
I need simple help with python?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I need simple help with python?
#1
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?
Reply
#2
You use the turn command to turn the turtle. You can pass it an angle in degrees to tell it how far to turn.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
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)
Reply
#4
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)
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#5
No, I need to import turtle and math, how to import both modules, import math,turtle doesn't work
Reply
#6
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?
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#7
I am not getting error it just doesn't open turtle window
Reply
#8
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.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020