Почему я получаю ошибку недопустимого имени команды «.numbers» в модуле черепахи?Python

Программы на Python
Ответить
Anonymous
 Почему я получаю ошибку недопустимого имени команды «.numbers» в модуле черепахи?

Сообщение Anonymous »

import random
import turtle
import time
bonus = 0
def main():
global writeT
writeT = turtle.Turtle()
global rchance
rchance = 0
Day = 0
global Steve
#0 name 1:days 2money 3health 4stress 5food
Steve = ["", 0, 200, 100, 0, 10]
DisplayTextOn("Welcome to Life Simulation!", 1)
DisplayTextOn("In this game, you will face many events \nthat you will have to go through.", 3)
DisplayTextOn("Your goal is to get thousand within one month.\nIf you get debt more than $1000, you lose.", 3)
DisplayTextOn("Also if your health is 0, you lose.\nStress level affects income level", 3)
DisplayTextOn("If your stress level is too high,\nHealth level will drop quickly.", 3)
DisplayTextOn("Good Luck!", 2)

turtle.bye()
Steve[0] = raw_input("Type your character's name :")

for days in range(30):
print "\nDay", days, "\n"
foodadjust(-2)
action()
stressadjust(5)
if Steve[4] > 50:
HPbonus(-10)
if days%7 == 0:
weeklypayment()
if days%30 == 0:
moneyinterest()
checkStatue()
if LostorNo() == True:
DisplayTextOn("Your health dropped to 0,\nor your debt is more than 1 grand.\nYou lost.", 2)
turtle.bye()
exit()
if WinorNo() == True:
DisplayTextOn("You succesfully collect 1 grand. Congrats!", 2)
turtle.bye()
exit()
Steve[1] += 1
def DisplayTextOn(text, t):
writeT.write(text, align='Center', font=('Calibri', 25, 'bold'))
time.sleep(t)
writeT.clear()
def RepeatText(text, inter, rept):
for repeating in range(rept):
writeT.write(text, align='Center', font=('Calibri', 25, 'bold'))
time.sleep(inter)
writeT.clear()
time.sleep(inter)
turtle.bye()

def moneyinterest():
Steve[2] += Steve[2]*0.005
def weeklypayment():
weekpay = 500 - 500*Steve[4]/100 + 50*bonus
print "You got weekly payment of $"+str(weekpay)
Steve[2] += weekpay
def action():
actnum = raw_input("Which action do you want to take?(1:eat, 2:work, 3:sleep, 4:go outside, 5:check statue)\nType num : ")
if actnum == "5":
checkStatue()
action()
elif actnum == "4":
outside()
elif actnum =="3":
sleep()
elif actnum =="2":
work()
elif actnum == "1":
eat()
elif actnum == "D":
developercommand()
else:
print "Invalid. Type again."
action()
def developercommand():
Steve[2] = float(input("Adjust money :"))
Steve[3] = float(input("Adjust health :"))
Steve[4] = float(input("Adjust stress :"))
Steve[5] = float(input("Adjust food :"))
action()
def work():
RepeatText("Working...", 1, 4)
print "You worked your second job."
print "You got paid $100."
foodadjust(-2)
Steve[2] += 100
def foodadjust(a):
Steve[5] += a
if Steve[5] < 0:
print "Your food is not enough"
print "Your health level decreased."
Steve[5] = 0
HPbonus(-10)
def stressadjust(a):
Steve[4] += a
if Steve[4] >= 100:
Steve[4] = 100
elif Steve[4] < 0:
Steve[4] = 0
def sleep():
RepeatText("Sleeping...", 1, 4)
print "You slept for the whole day. Your stress level reduced."
stressadjust(-15)
def eat():
RepeatText("Eating...", 1, 3)
print "You ate too much. Your stress level, food reduced. Health slightly decreased."
HPbonus(-2)
stressadjust(-25)
foodadjust(-4)
def lottery():
rchance = random.randrange(0, 50)
typeof = raw_input("What type of lottery do you want to buy? \n1:$5 lottery, $1000 if win\n2:$50 lottery, $10000 if win\n3:$500 lottery, $100000 if win :")
if typeof == "1":
Steve[2] -= 5
if rchance == 0:
print "You won! $100 into your bank account."
Steve[2] += 100
else:
print "You lost."
elif typeof == "2":
Steve[2] -= 50
if rchance == 0:
print "You won! $1000 into your bank account."
Steve[2] += 1000
else:
print "You lost."
elif typeof == "3":
Steve[2] -= 500
if rchance == 0:
print "You won! $10000 into your bank account."
Steve[2] += 10000
else:
print "You lost."
else:
print "Invalid. Type again."
lottery()
def buyfood():
amountfood = int(input("How much food do you want to buy? $10 each. : "))
print "It costed", str(amountfood*10) + "$"
Steve[2] -= amountfood*10
foodadjust(amountfood)
def gym():
RepeatText("Working out...", 1, 3)
print "You worked out in GYM. It costed $5."
print "Health level increased. Stress decreased."
Steve[2] -= 5
stressadjust(-20)
HPbonus(20)
#WHEN CHOSE TO GO OUTSIDE. 2 OPTIONS ARE THERE : EVENTS OR NORMAL OUTSIDE
def outside():
rchance = random.randrange(0, 4)
if rchance !=0:
print "You went outside."
normaloutside()
else:
events()
def normaloutside():
actnum = raw_input("Which action do you want to take?(1:walk, 2:run, 3:buy food, 4:buy lottery, 5:go to gym)\nType num : ")
if actnum == "1":
RepeatText("Walking...", 1, 3)
DisplayTextOn("You walked down the street.\nYou feel healthy.", 2)
print "You walked down the street. You feel healthy."
HPbonus(10)
elif actnum == "2":
print "You ran. You feel refreshed."
HPbonus(15)
stressadjust(-10)
foodadjust(-2)
elif actnum == "3":
buyfood()
elif actnum == "4":
lottery()
elif actnum == "5":
gym()
else:
print "Invalid. Type again."
normaloutside()
#EVENT SIDE*********************************************************************************************************************************************
def events():
rchance = random.randrange(1, 101)
if rchance 20 and rchance 40 and rchance 60 and rchance 80 and rchance 80:
print "You fought back. You successfully took them down."
print "Your health level decreased. Your stress greatly decreased."
stressadjust(-50)
HPbonus(-20)
else:
print "They took you down. They stole every money you have."
print "Your health level greatly decreased. Your stress greatly increased."
HPbonus(-40)
stressadjust(40)
if Steve[2] > 0:
Steve[2] = 0
else:
print "You gave them $200."
print "Your stress level increased."
stressadjust(10)
Steve[2] -= 200
def hitcar():
print "You just hit a car. But the owner of the car didn't see."
Response = raw_input("Run or Stay?(yes or no):").lower()
if Response == "yes":
print "You got arrested. You were able to get out by paying $1000 and $500 for automobile."
print "Your stress level increased."
Steve[4] += 20
Steve[2] -= 1500
else:
print "You paid $500 for the owner. Your stress level increased."
Steve[2] -= 500
Steve[4] += 5
def betterjob():
print "You got a chance to learn a better skill."
print "The education costs $200."
Response = raw_input("Pay or No?(yes or no):").lower()
if Response =="yes":
global bonus
print "You paid $200, and now you get bonus $50."
bonus += 1
Steve[2] -= 200
else:
print "Nothing happened."
def helppoor():
print "You saw a person begging for $20."
Response = raw_input("Give or No?(yes or no):").lower()
if Response == "yes":
DisplayTextOn("You gave him $20.\nYour stress level decreased.", 2)
print "You gave him $20."
print "Your stress level decreased."
stressadjust(-40)
Steve[2] -= 20
else:
DisplayTextOn("You ignored him.\nNothing happend.", 3)
print "You ignored him."
print "Nothing happened."
def gothitbycar():
DisplayTextOn("You got hit by a car.\nHe ran away.\nThe treatment costed $1000.\nYour stress increased.\nYour health is reset to 80.", 3)
print "You got hit by a car."
print "He ran away. The treatment costed $1000."
print "Your stress increased. Your health is reset to 80."
stressadjust(20)
Steve[2] -= 1000
Steve[3] = 80
#END OF EVENT***************************************************************3*********************************************************************************
def LostorNo():
if Steve[2] 100:
Steve[3] = 100
def checkStatue():
print "Health :", Steve[3],
print "Stress :", Steve[4],
print "Money : $"+str(Steve[2]),
print "Food :", Steve[5]

main()


Я создаю игру в качестве финального проекта для своего класса программирования, но получаю сообщение об ошибке (говорит: неверная команда. набор чисел) в функциональной части RepeatText(). Функция, которую я пытаюсь сделать, - это сделать моргающий текст черепахи. Например, если я поставлю «Работает...» для первого параметра, 1 для второго параметра и 3 для третьего параметра, он мигнет 3 раза с интервалом в 1 секунду. Когда я поместил тот же код в другую программу, все работало нормально. Кто-нибудь знает, почему я получаю эту ошибку?
Я использую Python 2 для этой функции, потому что мой класс использует Python 2.
Я попробовал сделать эту функцию отдельной, и она сработала совершенно нормально. Вот программа:
import turtle
import time
def RepeatText(text, inter, rept):
for i in range(rept):
writeT.write(text, align='Center', font=('Calibri', 25, 'bold'))
time.sleep(inter)
writeT.clear()
time.sleep(inter)
turtle.bye()
def main():
global writeT
writeT = turtle.Turtle()
excess()
def excess():
RepeatText("Blinking", 0.5, 3)

main()



Подробнее здесь: https://stackoverflow.com/questions/764 ... tle-module
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Python»