Tuesday, October 9, 2018

graphics python

Vans.py

# determine the number of vans needed

def main():
    people=int(input("Enter the number of passengers: "))
    vanLoad=8
    numOfVans=people//vanLoad
    leftOver=people % vanLoad #modulus
    print("number of vans: ", numOfVans)
    print("Left over people", leftOver)
    #print ("If any people are left over order another van")
    if leftOver > 0:
        numOfVans = numOfVans + 1
    
    print ("you will need ", numOfVans, "vans")


main()

graphicsstuff.py

#import graphics
from graphics import *

def main():
    win =GraphWin("First graphics", 400,500)
    rec=Rectangle(Point(100,100), Point(300,300))
    rec.setFill('Blue')
    rec.draw(win)
    point=Point(200,200)
    circ=Circle(point,100)
    circ.setFill('Red')
    circ.draw(win)
    line = Line(Point(100,280), Point(280,280))
    line.setWidth(10)
    line.draw(win)
    win.getKey()

main()

ConvertForm.py

from graphics import *

def main():
    win=GraphWin("Celsius Converter", 400, 300)
    win.setCoords(0.0,0.0,3.0,4.0)
    Text(Point(1,3), "Celsius Temperature: ").draw(win)
    Text(Point(1,1), "Fahrenheit temperature: ").draw(win)
    inputText=Entry(Point(2.25,3),5)
    inputText.setText("0.0")
    inputText.draw(win)
    outputText=Text(Point(2.25,1), "")
    outputText.draw(win)
    button=Text(Point(1.5,2.0),"convert it")
    button.draw(win)
    Rectangle(Point(1,1.5), Point(2,2.5)).draw(win)

    win.getMouse()

    celsius = float(inputText.getText())
    fahrenheit=9.0/5.0 * celsius + 32

    outputText.setText(round(fahrenheit, 2))
    button.setText("Quit")

    
    win.getMouse()
    win.close()
main()

No comments:

Post a Comment