I need help with this code, I have it started here
import sys
import turtle
menu = "Press 1 for Flower"
UserChoice = input(menu)
#function to draw squares
def draw_square(square):
for i in range(0,2):
square.forward(100)
square.right(70)
square.forward(100)
square.right(110)
#function to draw flower
def draw_flower(petalNumber):
window = turtle.Screen()
window.bgcolor("yellow")
pen = turtle.Turtle()
pen.shape("triangle")
pen.color("red")
for number in range(0,petalNumber):
draw_square(pen)
pen.right(360/petalNumber)
for i in range(0,4):
pen.circle(20)
pen.right(90)
pen.right(90)
pen.forward(300)
pen.right(90)
draw_square(pen)
pen.left(180)
draw_square(pen)
pen.left(270)
pen.forward(200)
window.exitonclick()
#function for original art
def originalArt():
print("This function will draw the original art")
#function for colorful art
def colorfulArt():
print("This function will draw the colorful art")
#if statement check the user choice
if(UserChoice == "1"):
numberOfPetals= int(input("How many petals?"))
#the next line calls the draw_flower function
draw_flower(numberOfPetals)
elif(UserChoice == "2"):
originalArt() #this line calls the originalArt function
elif(UserChoice == "3"):
colorfulArt()

Following is the complete functionality in the python implementation. Attaching snapshots for the code.


I have tried to keep the code as simple as possible. Hope that helps. Thanks!.
I need help with this code, I have it started here import sys import turtle menu...
I cannot run this code! Please explain and fix it for me import turtle import random # Approximate size of turtle objects in pixels BODY_SIZE = 80 # Half if the body size for collision detection with the edge of the screen HALF_BODY_SIZE = BODY_SIZE / 2 # if enemies get this close to friend there is collision COLLISION_DISTANCE = 5 # The window size SIZE = 500 # inner boundary within window for reversing the direction of enemies LOWER_BOUND...
Using python
Here is the code
import turtle
def draw_triangle(vertex, length, k):
'''
Draw a triangle at depth k given the bottom vertex.
vertex: a tuple (x,y) that gives the coordinates of the bottom
vertex.
When k=0, vertex is the left bottom vertex for the outside
triangle.
length: the length of the original outside triangle (the
biggest one).
k: the depth of the input triangle.
As k increases by 1, the triangles shrink to a smaller
size.
When k=0, the...
Answer must be in Python 3
Answer:
import turtle
def trifecta(size,angle,num):
for i in range(num):
tri(t,size)
t.right(angle)
t = turtle.Turtle()
s = turtle.Screen()
trifecta(100,25,5)
Question 11 Part b (10 points) Write a function named trifecta() that takes three parameters: 1. size 2. angle 3. num trifecta() should call tri() repeatedly so as to draw num triangles, each with sides of length size. Each triangle should be oriented angle degrees clockwise from the preceding triangle. trifecta() should create a turtle and...
In Python, starting with the 8x8 board solution that will be appended here add the following functionality: 1) Add code to create a list, containing 8 lists, with each of the 8 lists containing 8 null strings as values. Call the list of lists board. code provided by prof: import turtle validMovesList=['A0','A2','A4','A6','B1','B3','B5','B7', 'C0','C2','C4','C6','D1','D3','D5','D7', 'E0','E2','E4','E6','F1','F3','F5','F7', 'G0','G2','G4','G6','H1','H3','H5','H7','quit'] def drawSquare(t,length,color): t.fillcolor(color) t.begin_fill() for num in range(4): t.forward(length) t.left(90) t.end_fill() def drawRow(t,length,color1,color2): for i in range(4): drawSquare(t,length,color1) t.forward(length) drawSquare(t,length,color2) t.forward(length) def drawCircleFilled(t,size,color): t.fillcolor(color) t.begin_fill()...
Need help writing this code in python.
This what I have so far.
def display_menu():
print("======================================================================")
print(" Baseball Team Manager")
print("MENU OPTIONS")
print("1 - Calculate batting average")
print("2 - Exit program")
print("=====================================================================")
def convert_bat():
option = int(input("Menu option: "))
while option!=2:
if option ==1:
print("Calculate batting average...")
num_at_bats = int(input("Enter official number of at bats:
"))
num_hits = int(input("Enter number of hits: "))
average = num_hits/num_at_bats
print("batting average: ", average)
elif option !=1 and option !=2:
print("Not a valid...
I need help in Python. This is a two step problem So I have the code down, but I am missing some requirements that I am stuck on. Also, I need help verifying the problem is correct.:) 7. Random Number File Writer Write a program that writes a series of random numbers to a file. Each random number should be in the range of 1 through 500. The application should let the user specify how many random numbers the file...
Here is my code for minesweeper in python and it has something
wrong. Could you please help me to fix it?
import tkinter as tk
import random
class Minesweeper:
def __init__(self):
self.main = tk.Tk()
self.main.title("mine sweeper")
self.define_widgets()
self.mines = random.sample( [(i,j) for i in range(25) for j in
range(50) ],self.CustomizeNumberOfMines())
print(self.mines)
self.main.mainloop()
self.CustomizeNumberOfMines()
def define_widgets(self):
""" Define a canvas object, populate it with squares and
possible texts """
self.canvas = tk.Canvas(self.main, width = 1002, height=502,
bg="#f0f0f0")
self.canvas.grid(row=0, column=0)
self.boxes =...
9p
This is for Python I need help.
Pet #pet.py mName mAge class Pet: + __init__(name, age) + getName + getAge0 def init (self, name, age): self.mName = name self.mAge = age Dog Cat def getName(self): return self.mName mSize mColor + __init__(name, age,size) + getSize() + momCommento + getDog Years() +_init__(name, age,color) + getColor + pretty Factor + getCatYears def getAge(self): return self.mAge #dog.py import pet #cat.py import pet class Dog (pet. Pet): class Cat (pet. Pet): def init (self,...
I need help with my python class. thanks! Question 12 Code Example 4-4 main program: import arithmetic as a def multiply(num1, num2): product = num1 * num2 result = a.add(product, product) return result def main(): num1 = 4 num2 = 3 answer = multiply(num1, num2) print("The answer is", answer) if __name__ == "__main__": main() arithmetic module: def add(x, y): z = x + y return z Refer to Code...
Hello I need help with python programming here is my code # Trivia Challenge # Trivia game that reads a plain text file import sys def open_file(file_name, mode): """Open a file.""" try: the_file = open(file_name, mode) except IOError as e: print("Unable to open the file", file_name, "Ending program.\n", e) input("\n\nPress the enter key to exit.") sys.exit() else: return the_file def next_line(the_file): """Return next line from the trivia file, formatted.""" line = the_file.readline() line = line.replace("/", "\n") return line def next_block(the_file):...