Jump to content

So I'm attempting to make a program that takes user input for number of sides, side lengths, angle of turns, and pen color. This is the code I have so far but I can't get it to run without the following: "Traceback; ValueError: invalid literal for int() with base 10: 'Enter how many sides does your object have?:'" I have went around and around Google and YouTube and all I can find is people making programs that simply allow the user to type "triangle" , "Square" etc. Any tips or assistance would be greatly appreciated.

# Ask user for number of sides, angle of turns and pencolor

num_sides = input(int('Enter how many sides does your object have?:'))
side_length = input(int('How long should each side be?:'))
angle_turn = input(int('Enter an angle for each corner:'))
pen_color = input('Enter a color for your object:')

#Drawing function

import turtle

def draw_object():
	turtle.pencolor(pen_color)

	for side in range(1, num_sides):
		turtle.forward(side_length)
		turtle.left(angle_turn)

draw_object()

 

Link to comment
https://linustechtips.com/topic/1125820-basic-help-with-turtle-in-python/
Share on other sites

Link to post
Share on other sites

You need to declare the input as an integer, not the input text

Community Standards || Tech News Posting Guidelines

---======================================================================---

CPU: R5 9600X || GPU: RX 9070 XT|| Memory: 32GB || Cooler: Peerless Assassin || PSU: RM850e|| Case: Lian Li A3

Link to post
Share on other sites

1 hour ago, BlueSpartan said:

Any tips or assistance would be greatly appreciated.

To expand on @Slottr remark:

# What you have
int numSides = input(int("prompt the user"))

# What you should have
int numSides = int(input("prompt the user"))


Order of operations is important here. In the first example you're attempting to feed the input() function the output from casting the string literal "prompt the user".

What you really want to do is cast the output of the input() function to an int.

ENCRYPTION IS NOT A CRIME

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×