def main(): # The choice variable controls the loop # and holds the user's menu choice. choice = 0 while choice != QUIT_CHOICE: # display the menu. display_menu() # Get the user's choice. choice = int(input('Enter your choice: ')) # Perform the selected action. if choice == AREA_CIRCLE_CHOICE: radius = float(input("Enter the circle's radius: ")) print('The area is', circle.area(radius)) elif choice == CIRCUMFERENCE_CHOICE: radius = float(input("Enter the circle's radius: ")) print('The circumference is', circle.circumference(radius)) elif choice == AREA_CYLINDER_CHOICE: radius = float(input("Enter the circle's width: ")) height = float(input('Enter the height of cylinder')) area = 2 * circle.area(radius) + circle.circumference( radius) * height print('The total area of cylinder is', area) elif choice == QUIT_CHOICE: print('Exiting the program. . .') else: print('Error: invalid selection.')
def main(): # Переменная choice управляет циклом # и содержит вариант выбора пользователя. choice = 0 while choice != QUIT_CHOICE: # Показать меню. display_menu() # Получить вариант выбора пользователя. choice = int(input('Выберите вариант: ')) # Выполнить выбранное действие. if choice == AREA_CIRCLE_CHOICE: radius = float(input('Введите радиус круга: ')) print('Площадь равна', circle.area(radius)) elif choice == CIRCUMFERENCE_CHOICE: radius = float(input('Введите радиус круга: ')) print('Длина окружности равна', circle.circumference(radius)) elif choice == AREA_RECTANGLE_CHOICE: width = float(input('Введите ширину прямоугольника: ')) length = float(input("Введите длину прямоугольника: ")) print('Площадь равна', rectangle.area(width, length)) elif choice == PERIMETER_RECTANGLE_CHOICE: width = float(input('Введите ширину прямоугольника: ')) length = float(input('Введите длину прямоугольника: ')) print('Периметр равен', rectangle.perimeter(width, length)) elif choice == QUIT_CHOICE: print('Выходим из программы...') else: print('Ошибка: недопустимый выбор.')
def main(): choice = 0 while choice != QUIT_CHOICE: display_menu() choice = int(input("Enter your choice: ")) if choice == AREA_CIRCLE: radius = float(input("Enter the radius of the circle: ")) print("The area of the circle is ", circle.area(radius), "units") elif choice == CIRCUMFERENCE_CIRCLE: radius = float(input("Enter the radius of the circle: ")) print("The circumference of the circle is ", circle.circumference(radius), "units") elif choice == AREA_RECTANGLE: length = float(input("Enter the length of the rectangle: ")) width = float(input("Ente the width of the rectangle: ")) print("The area of the rectangle is ", rectangle.area(length, width), "units") elif choice == PERIMETER_RECTANGLE: length = float(input("Enter the length of the rectangle: ")) width = float(input("Ente the width of the rectangle: ")) print("The perimeter of the rectangle is ", rectangle.perimeter(length, width), "units") elif choice == QUIT_CHOICE: print("Exiting the program.....") else: print("Error, you selected an invalid choice!!!")
def main(): radius = random.randrange(1, 10) #radius = float(input('Enter the radius of the cylinder')) height = float(input('Enter the height of cylinder')) TSA = 2 * circle.area(radius) + height * circle.circumference(radius) print(TSA)
def main(): choice = 0 while choice != QUIT_CHOICE: display_menu() choice = int(input('Wybierz opcje: ')) if choice == AREA_CIRCLE_CHOICE: promien = float(input('Podaj promien okregu: ')) print('Pole powierzchni wynosci ', circle.area(promien)) elif choice == CIRCUMREFERENCE_CHOICE: promien = float(input('Podaj promien okregu:')) print('Pole powierzchni wynosi ', circle.circumference(promien)) elif choice == AREA_RECTANGLE_CHOICE: dlugosc = float(input('Podaj dlugosc podstawy: ')) szerokosc = float(input('Podaj szerokosc podstawy ')) print('Pole powierzchni prostokata wynosi: ', rectangle.area(dlugosc, szerokosc)) elif choice == PERIMETER_RECTANGLE_CHOICE: dlugosc = float(input('Podaj dlugosc podstawy: ')) szerokosc = float(input('Podaj szerokosc podstawy ')) print('Obwod wynosi: ', rectangle.perimeter(dlugosc, szerokosc)) elif choice == QUIT_CHOICE: break else: print('Bledna opcja')
def main(): # The choice variable controls the loop # and holds the user's menu choice. choice = 0 while choice != QUIT_CHOICE: # display the menu. display_menu() # Get the user's choice. choice = int(input('Enter your choice: ')) # Perform the selected action. if choice == AREA_CIRCLE_CHOICE: radius = float(input("Enter the circle's radius: ")) print('The area is', circle.area(radius)) elif choice == CIRCUMFERENCE_CHOICE: radius = float(input("Enter the circle's radius: ")) print('The circumference is', \ circle.circumference(radius)) elif choice == AREA_RECTANGLE_CHOICE: width = float(input("Enter the rectangle's width: ")) length = float(input("Enter the rectangle's length: ")) print('The area is', rectangle.area(width, length)) elif choice == PERIMETER_RECTANGLE_CHOICE: width = float(input("Enter the rectangle's width: ")) length = float(input("Enter the rectangle's length: ")) print('The perimeter is', \ rectangle.perimeter(width, length)) elif choice == QUIT_CHOICE: print('Exiting the program...') else: print('Error: invalid selection.')
def main(): # the choice variable controls the loop and holds the users menu choice choice = 0 while choice != QUIT_CHOICE: # display the menu print() display_menu() # get the users choice choice = int(input('Enter your choice: ')) print() # perform the selected action if choice == AREA_CIRCLE_CHOICE: radius = float(input('Enter the circles radius: ')) print('The ares is', circle.area(radius)) elif choice == CIRCUMFERENCE_CHOICE: radius = float(input('Enter the circles radius: ')) print('The circumference is', circle.circumference(radius)) elif choice == AREA_RECTANGLE_CHOICE: width = float(input('Enter the rectangles width: ')) length = float(input('Enter the rectangles length: ')) print('The ares is', rectangle.area(width, length)) elif choice == PERIMETER_CHOICE: width = float(input('Enter the rectangles width: ')) length = float(input('Enter the rectangles length: ')) print('The perimeter is', rectangle.perimeter(width, length)) elif choice == QUIT_CHOICE: print('Exiting the program') else: print('Error: invalid selection')
def main(): # The choice variable controls the loop # and holds the user's menu choice. choice = 0 while not (choice == 5): # display the menu. display_menu() # Get the user's choice. choice = int(input('Enter your choice: ')) # Perform the selected action. if choice == 1: r = float(input("Enter the circle's radius: ")) print('The area is {:.3f}.'.format(circle.area(r))) elif choice == 2: radius = float(input("Enter the circle's radius: ")) print('The circumference is {:.3f}'.format( circle.circumference(radius))) elif choice == 3: width = float(input("Enter the rectangle's width: ")) length = float(input("Enter the rectangle's length: ")) print('The area is {:.3f}'.format(rectangle.area(width, length))) elif choice == 4: width = float(input("Enter the rectangle's width: ")) length = float(input("Enter the rectangle's length: ")) print('The perimeter is {:.3f}'.format( rectangle.perimeter(width, length))) elif choice == 5: print("Exiting the program...") else: print("Error: invalid selection.")
def main(): choice = 0 while choice != QUIT_CHOICE: display_menu() choice = int(input("Enter your choice: ")) if choice == AREA_OF_CIRCLE_CHOICE: radius = float(input("Enter the circle's radius: ")) print("The area is", circle.area_radius(radius)) elif choice == CIRCUMFERENCE_CHOICE: width = float(input("Enter the rectangle's width: ")) length = input("Enter the rectangle's length: ") print("The circumference is", circle.circumference(width, length)) elif choice == AREA_RECTANGLE_CHOICE: width = float(input("Enter the rectangle's width: ")) length = input("Enter the rectangle's length: ") print("The area is", rectangle.area(width, length)) elif choice == PERIMETER_RECTANGLE_CHOICE: width = float(input("Enter the rectangle's width: ")) length = float(input("Enter the rectangle's length: ")) print("The perimeter is", rectangle.perimeter(width, length)) elif choice == QUIT_CHOICE: print("Exiting the program...") else: print("Error: Invalid selection.")
def main(): choice = 0 while choice != QUIT_CHOICE: display_menu() choice = int(input('Enter your choice: ')) if choice == AREA_CIRCLE_CHOICE: radius = float(input("Enter the circle's radius: ")) print('The area is', circle.area(radius)) elif choice == CIRCUMFERENCE_CHOICE: radius = float(input("Enter the circle's radius: ")) print('The circumference is', \ circle.circumference(radius)) elif choice == AREA_RECTANGLE_CHOICE: width = float(input("Enter the rectangle's width: ")) length = float(input("Enter the rectangle's length: ")) print('The area is', rectangle.area(width, length)) elif choice == PERIMETER_RECTANGLE_CHOICE: width = float(input("Enter the rectangle's width: ")) length = float(input("Enter the rectangle's length: ")) print('The perimeter is', \ rectangle.perimeter(width, length)) elif choice == QUIT_CHOICE: print('EXITING the program...') else: print('Error: invalid selection.')
def main(): ''' choice variable controls the loop and the user menu''' choice = 0 while choice != 5: # display the menu. display_menu() # Get the user's choice. choice = input ( ' Enter your choice : ' ) # Perform the selected action. if choice == 1: radius = input("Enter the circle's radius: " ) print 'The area is', circle.area(radius) elif choice == 2: radius = input( "Enter the circle's radius: " ) print ' The circumference is ' , circle.circumference(radius) elif choice == 3: width = input("Enter the rectangle's width: " ) length = input("Enter the rectangle's length: " ) print 'The area is', rectangle.area(width, length) elif choice == 4: width = input("Enter the rectangle's width: " ) length = input("Enter the rectangle's length: ") print 'The perimeter is ' , \ rectangle.perimeter(width, length) elif choice == 5: print 'Exiting the program . . . ' else: print 'Error: invalid selection.'
def surface(height, radius): #surface area = (2 * pi * radius * height) + (2 * pi * r^2) # = (base circumference * height) + (2 * base area) # = area of sides + area of two ends ends_area = 2 * circle.area(radius) sides_area = circle.circumference(radius) * height return ends_area + sides_area
def main(): choise = 0 while choise != QUIT_CHOICE: display_menu() #получить ввод пользователя choise = int(input('Введите вариант: ')) if choise == AREA_CIRCLE_CHOISE: radius = float(input('Введите радиус круга: ')) print('Площадь окружности равна', circle.area(radius)) elif choise == CIRCUMFERENCE_CHOISE: radius = float(input('Введите радиус круга: ')) print('Длина окружности равна', circle.circumference(radius)) elif choise == AREA_RECTANGLE_CHOISE: width = float(input("Введите ширину прямоугольника: ")) length = float(input("Введите длину прямоугольника: ")) print('Площадь равна', rectangle.area(width,length)) elif choise == PERIMETER_RECTANGLE_CHOISE: width = float(input("Введите ширину прямоугольника: ")) length = float(input("Введите длину прямоугольника: ")) print('Площадь равна', rectangle.perimeter(width, length)) else: print('Ошибка: недопустимый выбор')
def main(): choice = 0 while choice != QUIT_CHOICE: display_menu() choice = int(input('Wybierz opcję: ')) # Wykonanie wybranej akcji. if choice == AREA_CIRCLE_CHOICE: radius = float(input("Podaj promień okręgu: ")) print('Pole powierzchni wynosi', circle.area(radius)) elif choice == CIRCUMFERENCE_CHOICE: radius = float(input("Podaj promień okręgu: ")) print('Obwód wynosi', circle.circumference(radius)) elif choice == AREA_RECTANGLE_CHOICE: width = float(input("Podaj długość prostokąta: ")) length = float(input("Podaj szerokość prostokąta: ")) print('Pole powierzchni wynosi', rectangle.area(width, length)) elif choice == PERIMETER_RECTANGLE_CHOICE: width = float(input("Podaj długość prostokąta: ")) length = float(input("Podaj szerokość prostokąta: ")) print('Obwód wynosi', rectangle.perimeter(width, length)) elif choice == QUIT_CHOICE: print('Zakończenie działania programu...') else: print('Błąd: nieprawidłowa opcja.')
def main(): radius = read_radius() while radius != 0: area = circle.area(radius) circumference = circle.circumference(radius) print('Area is ' + str(area)) print('Circumference is ' + str(circumference)) radius = read_radius()
def main(): radiusA = 3 print('{:.2f}'.format(c.circumference(radiusA))) print(variableLengthPosPar(3, 4, "hello", True, 3)) print(variableLengthKeywordPar(3, 5, bob=1, sally=2)) #print(reverse("python")) tuple1 = (1, 3, 8, 'hey') print(tuple1) s1 = {5, 4, 4, 10} s2 = {5, 4, 1} print(s1.union(s2))
def main(): SELECTION = str(input("Calculate for a (c)ircle or (r)ectangle: ")) if SELECTION == 'c': radius = int(input("Enter the radius of the circle: ")) print("The area of the circle is: ", circle.area(radius)) print("The circumference of the circle is: ",\ circle.circumference(radius)) if SELECTION == 'r': width = int(input("Enter the width of the rectangle: ")) length = int(input("Enter the length of the rectangle: ")) print("The area of the rectangle is: ",\ rectangle.area(width=width,length=length)) print("The perimeter of rectangle is: ",\ rectangle.perimeter(width=width,length=length))
def main(): # The choice variable controls the loop # and hold the user's menu choice choice = 0 while choice != QUIT_CHOICE: # display menu display_menu() # get user's choice choice = int(input("Enter your choice: ")) # Perform the calculation selected if choice == AREA_CIRCLE_CHOICE: radius = float(input("Enter the circle's radius: ")) print("The area is", circle.area(radius)) elif choice == CIRCUMFERENCE_CHOICE: radius = float(input("Enter the circle's radius: ")) print("The circumference is", circle.circumference(radius)) elif choice == AREA_RECTANGLE_CHOICE: width = float(input("Enter the rectangle's width: ")) length = float(input("Enter the rectangle's lenght: ")) print("The area is", rectangle.area(width, length)) elif choice == PERIMETER_REC_CHOICE: width = float(input("Enter the rectangle's width: ")) length = float(input("Enter the rectangle's lenght: ")) print("The parimeter is", rectangle.perimeter(width, length)) elif choice == QUIT_CHOICE: print("Exiting the program.......") else: print("Error: invalid entry")
def main(): """ Calculates the area and perimeter of rectangle or circle """ print('This program calculates area and perimeter of a rectangle or circle.') choice = int(input('Enter 1 for rectangle or 2 for circle: ')) if choice == 1: length = float(input('Enter length of rectangle: ')) width = float(input('Enter width of rectangle: ')) rect_area = rectangle.area(length, width) rect_perimeter = rectangle.perimeter(length, width) print('Area:', rect_area, 'Perimeter:', rect_perimeter) elif choice == 2: print('Value of PI in circulations:', circle.PI) radius = float(input('Enter radius of circle: ')) circle_area = circle.area(radius) circle_perimeter = circle.circumference(radius) print('Area:', circle_area, 'Perimeter:', circle_perimeter) else: print('Invalid choice')
def main(): print( 'Program geometria pozwala obliczyć pole i obwód koła, prostokąta i trójkata.' ) # W pętli while pobierana jest od użytkownika liczba całkowita # odpowiadająca wybranej czynności (od 1 do 5), a następnie # w bloku if-elif-else odczytywane są dane i wykonywane obliczenia. choice = 0 #inicjalizacja zmiennej choice while choice != QUIT_CHOICE: display_menu() #wyświetlenie menu #pobranie wartości od użytkownika choice = int(input('Wybierz opcję: ')) #wybór czynności if choice == AREA_CIRCLE_CHOICE: #pole koła radius = circle.get_radius() print('Pole koła wynosi', circle.area(radius)) elif choice == CIRCUMFERENCE_CHOICE: #obwód koła radius = circle.get_radius() print('Obwód koła wynosi', circle.circumference(radius)) elif choice == AREA_RECTANGLE_CHOICE: #pole prosokąta (length, width) = rectangle.get_dimensions() print('Pole prostokąta wynosi', rectangle.area(length, width)) elif choice == PERIMETER_RECTANGLE_CHOICE: #obwód prostokąta (length, width) = rectangle.get_dimensions() print('Obwód prostokąta wynosi', rectangle.perimeter(length, width)) elif choice == AREA_TRIANGLE_CHOICE: #pole trójkąta (a, b, c) = triangle.get_lengths() print('Pole trójkąta wynosi', triangle.area(a, b, c)) elif choice == PERIMETER_TRIANGLE_CHOICE: #obwód trójkąta (a, b, c) = triangle.get_lengths() print('Obwód trójkąta wynosi', triangle.perimeter(a, b, c)) elif choice == QUIT_CHOICE: #koniec programu print('Zakończenie działania programu.') else: #wartość spoza listy print('Błąd: nieprawidłowa opcja.')
def main(): choice = 0 while choice != quit_choice: display_menu() choice = int(int('Enter your choice: ' )) if choice == area_circle_choice: radius = float(input"Enter the circle's radius: ")) print('The area is', circle.area(radius)) elif choice == circumference_choice: radius = float(input("Enter the circle's radius: ")) print('Ther circumference is', circle.circumference(radius)) elif choice == area_rectangle_choice: width = float(input("Enter the rectangle's width: ")) length = float(input("Enter the rectabgle's length: ")) print('The area is', rectangle.area(width,length)) elif choice == perimeter_rectangle_choice: width = float(input("Enter the rectangle's width: ")) length = float(input("Enter the rectangle's length: ")) print('The perimeter is', rectangle.perimeter(width, length)) elif choice == quit_choice: print('Exitting the program...') else : print('Error: invalid selection.')
def handle_circumference_of_circle(): radius = float(input("Enter the circles radius: ")) return "The circumference is" + str(circle.circumference(radius))
def handle_circumference(): radius = float(input("Enter the circle's radius: ")) print(str.format("The area is {:.2f}", circle.circumference(radius)))
import circle pi = 3 print(pi) print(circle.pi) print(circle.area(3)) print(circle.circumference(3))
#!/usr/bin/env python # coding: utf-8 # In[2]: import circle # In[ ]: pi = 3# 对于circle内部模块而言,这里的pi属于外部变量,不会对circle内部模块的pi变量造成影响 print('pi is',pi) print('cicle.pi',circle.pi) print('circle.area',circle.area(3)) print('circle.circumference',circle.circumference(pi)) print('circle.sphereSurface',circle.sphereSurface(pi))
import circle rad = float(input("Radius of a circle: ")) print("Area: ", circle.area(rad)) print("Circumference: ", circle.circumference(rad))
def testCircle(): print(circle.PI) print(circle.area(3)) print(circle.circumference(3)) print(circle.sphereSurface(3)) print(circle.sphereVolume(3))
#def displaymenu(): while (ch == 'y'): print("menu") print("1.area of the circle") print("2.circumference of a circle") print("3.area of a rectngle") print("4.perimeter of a rectangle") print("5.quit") choice = int(input("enter your choice:")) if (choice == 1): radius = int(input("enter the circle's radius:")) print("the area is:", circle.area(radius)) elif (choice == 2): radius = int(input("enter the circle's radius:")) print("the circumference is", circle.circumference(radius)) elif (choice == 3): width = int(input("enter the rectangle's width:")) length = int(input("enter the rectangle's length:")) print("the areais", rectangle.area(width, length)) elif (choice == 4): width = int(input("enter the rectangle's width:")) length = int(input("enter the rectangle's length:")) print("the perimeter is", rectangle.perimeter(width, length)) elif (choice == 5): print("exiting the program..") else: print('error : invalid selection')
return fib(x-1) + fib(x-2) def testFib(n): for i in range(n+1): global numFibCalls numFibCalls = 0 print('fib of', i, '=', fib(i)) print('fib called', numFibCalls, 'times.') #Page 52, See circle.py #Page 52 import circle print( circle.pi) print( circle.area(3)) print( circle.circumference(3)) print( circle.sphereSurface(3)) from circle import * print(pi) print(circle.pi) #Page 53 nameHandle = open('kids', 'w') for i in range(2): name = input('Enter name: ') nameHandle.write(name + '\n') nameHandle.close() #Page 54 nameHandle = open('kids', 'r')
import circle from rectangle import * from graphics.3-D graphics import cuboid,sphere a=float(input('Enter length of the rectangle: ')) b=float(input('Enter breadth of the rectangle: ')) perimeter(a,b) r=float(input('Enter the radius of the circle: ')) circle.circumference(r) l=float(input('Enter length of the cuboid: ')) b=float(input('Enter breadth of the cuboid: ')) h=float(input('Enter height of the cuboid: ')) cuboid.perimeter(l,b,h) r=float(input('Enter the radius of the sphere: ')) sphere.perimeter(r)
import circle print circle.pi print circle.area(3) print circle.circumference(3) print circle.sphereSurface(3)
def handle_circumference_of_circle(CIRCUMFERENCE_CHOICE): radius = float(input("Enter the circle's radius: ")) return "The circumference is" + " " + str(circle.circumference(radius))
isPal = True while i <= j: if s[i] != s[j]: isPal = False break i += 1 j -= 1 return isPal # Testing my Circle module print("\n Testing Modules") print(circle.pi) print(circle.area(5)) print(circle.circumference(5)) print(circle.sphereSurface(5)) print(circle.sphereVolume(5)) # Testing File Handles print("\n Testing File Handles") playerHandle = open("Players", "w") # creates a file "Players" and returns a file handle for the file playerHandle.write("11.John\n") playerHandle.write("8.Sam\n") playerHandle.write("7.Moses\n") playerHandle.close() playerHandle = open("Players", "a") # opens file for appending and returns file handle playerHandle.write("10.Domingo\n") playerHandle.write("3.Timothy\n") playerHandle.close()
return fib(x-1) + fib(x-2) def testFib(n): for i in range(n+1): global numFibCalls numFibCalls = 0 print 'fib of', i, '=', fib(i) print 'fib called', numFibCalls, 'times.' #Page 52, See circle.py #Page 52 import circle print circle.pi print circle.area(3) print circle.circumference(3) print circle.sphereSurface(3) from circle import * print pi print circle.pi #Page 53 nameHandle = open('kids', 'w') for i in range(2): name = raw_input('Enter name: ') nameHandle.write(name + '\n') nameHandle.close() #Page 54 nameHandle = open('kids', 'r')