Write a program that asks the user for a color, a line width, a line length and a shape. The shape should be either a line, a triangle, or a square. Use turtle graphics to draw the shape that the user requests of the size, color, line width and line length that the user requests. For example, if these are the user choices for color, width, line length and shapePython: Напишите программу, которая запрашивает у пользователя цвет, ширину линии, длину линии и форму
какой цвет? синий
какой линия ширина? 25
какой длина строки? 100
линия, треугольник или квадрат? треугольник
Это моя попытка:
color = input('Enter your preferred turtle line color: ')
width = input('Enter your preferred turtle line width: ')
length = input('Enter your preferred turtle line length: ')
shape = input('Specify whether you want to draw a line, triangle, or square: ')
import turtle
s = turtle.Screen()
t = turtle.Turtle()
t.pencolor(color)
t.pensize(width)
if shape == 'line':
t.forward(length)
elif shape == 'triangle':
t.forward(length)
t.right(45)
t.forward(length)
t.right(90)
t.forward(length)
else:
t.forwad(length)
t.right(90)
t.forwad(length)
t.right(90)
t.forwad(length)
t.right(90)
t.forwad(length)
Я получаю эту ошибку:
Traceback (most recent call last):
File "<pyshell#42>", line 4, in <module>
t.forward(length)
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/turtle.py", line 1637, in forward
self._go(distance)
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/turtle.py", line 1604, in _go
ende = self._position + self._orient * distance
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/turtle.py", line 257, in __mul__
return Vec2D(self[0]*other, self[1]*other)
TypeError: can't multiply sequence by non-int of type 'float'
Может кто-то пожалуйста, объясните, почему длина в передних команд не будет идти до конца?
Попробуйте отформатировать ваш вопрос, так что это более читаемым – taesu
http://stackoverflow.com/help/formatting – user3467349
Я думаю, что вы RINPUT переменные, .e.g. длина - все строки. заставить их плавать или интигеры. – Marcin