Python Question
Description
In this we are going to combine what we have been doing with turtle and the math library, functions, and random.
Here is a piece of starter code:
import math
import turtle
import random
# Starter Code
def randomTurtle():
for count in range(10):
choice = random.randint(1,2)
if (choice==1):
turtle.forward(random.randint(5, 50))
elif(choice==2):
turtle.right(random.randint(1,359))
def testTurtle():
turtle.forward(100)
turtle.left(90)
turtle.forward(100)
# Call this when turning it in
randomTurtle()
# Call this when testing to make sure you have the correct answer
testTurtle()
You are going to create a new function to tell how far the turtle has travelled. Your function will be defined as:
def distance(x, y):
It will need to return the distance back to the main program which you will print out. I would suggest using the testTurtle function to see if it is working. If it is working correctly, you will get 141.42 as the correct answer. When you turn it in, do NOT call testTurtle in your code.
To get the turtle’s position you can use
turtle.xcor()
turtle.ycor()
Rubric
1 – Name/Class/Assignment Comment
1 – Comments/Code Style/Output
1 – Including a call to the randomTurtle Function from starter code
1 – Creates function distance that takes in two values
1 – Calls function distance that takes in the position of the turtle
3 – Uses a math function to calculate the distance
3 – Returns the correct value
2 – Prints out the returned value
{IN ANOTHER FILE}
During my time as an undergraduate student at UCF, I enrolled in 4-5 courses a semester. When I would enroll using myUCF I would enroll in one class at a time. Once, I tried to enroll into six courses and it told me I was unable to do so. This wasn’t a technical limit, but a limit the university had placed on me. If I dropped a class, I would be able to enroll into the new class.
The Program
You are going to write a program that will ask the user which class they would like to take. They will input that class as a string. Your program should be able to handle both names of the class (Topics in Computer Science) or the course code (COP 2500C). After you insert the course in the list, you need to print out the course schedule. If you already have 5 courses in your list, you will print out the course schedule with the new class as the 6th course and ask the user which one they want to drop. They can input 6 to drop the one they just put in. You will need to not let the user put in any other number other than the 1-6, and will continue to prompt them until they put one in. The program ends when the user types in “EXIT” for the course name.
Rubric
1 – Header with name, course, date, assignment
1 – Style/Output/Comments
1 – Creates a list to store courses in
1 – Creates a loop that ends when exit is inputted
2 – Insert a course to the list within the loop
5 – Prints out the context of the list after each insert
1 – Checks if the list is too large and prompts for deletion
4 – Deletes the chosen course out of the list
2 – Keeps prompting until user choses a valid index range
Have a similar assignment? "Place an order for your assignment and have exceptional work written by our team of experts, guaranteeing you A results."