Что означает TypeError: не все аргументы, преобразованные во время форматирования строки, означают в Python - PullRequest
0 голосов
/ 01 октября 2011

вот моя первая программа, в основном она говорит вслух и разными голосами:

import os
print "Hello, Welcome to the speaking program"
speak = raw_input("What would you like to say?\n")
type = raw_input("Would you like\n1. Normal Voice\n2. High Pitched\n3. Low Pitched?\n4. Whisper\n5. Indian Voice\n Please choose 1,2,3,4 or 5\n")

if type == "1":
    os.system("say %s " % speak)
if type == "2":
   os.system("say -v good %s" % speak)
if type == "3":
    os.system("say -v bad %s" % speak)
if type == "4":
    os.system("say -v whisper %s" % speak)
if type == "5":
    os.system("say -v sangeeta $s" % speak)
if type < "5":
    os.system("echo that is not an option")

finish = raw_input("I have done the job, Pick an option\n1. Quit\n2. New Word\n3. Change Pitch\n")

if finish == "1":
    quit()
if finish == "2": 
    os.system("clear")
    os.system("python speak.py")
if finish == "3": 
    type2 = raw_input("Would you like\n1. Normal Voice\n2. High Pitched\n3. Low Pitched\nor\n4. Whisper voice?\n5.Indian Voice\n")    
    if type2 == "1":
        os.system("say %s " % speak)
    if type2 == "2":
        os.system("say -v good %s" % speak)
    if type2 == "3":
        os.system("say -v bad %s" % speak)
    if type == "4":
        os.system("say -v whisper %s" % speak)
    if type == "5":
        os.system("say -v Sangeeta %s" % speak)

    else:
        print "That is not an option"
        os.system("clear")
        os.system("python speak.py")

else:
    print "That is not an option !!! "
    os.system("clear")
    os.system("python speak.py")

finish = raw_input("I have done the job, Pick an option\n1. Quit\n2. New Word\n3. Change Pitch\n")
if finish == "1":
    os.system("logout")
    os.system("killall Terminal")
if finish == "2": 
    os.system("clear")
    os.system("python speak.py")
if finish == "3": 
    type3 = raw_input("Would you like \n1. Normal Voice\n2. High Pitched\n3. Low Pitched?\n4. Whisper voice\n5.Indian Voice\n")    
    if type3 == "1":
        os.system("say %s " % speak)
    if type3 == "2":
        os.system("say -v good %s" % speak)
    if type3 == "3":
        os.system("say -v bad %s" % speak)
    if type3 == "4":
        os.system("say -v whisper %s" % speak)
    if type3 == "5":
        os.system("say -v Sangeeta %s" % speak)
    else:
        print "That is not an option"
        os.system("clear")
        os.system("python speak.py")

и это ошибка:

Shameers-MacBook-Pro:Test Programs Shameer$ !!
python speak.py 
Hello, Welcome to the speaking program
What would you like to say?
hello
Would you like
1. Normal Voice
2. High Pitched
3. Low Pitched?
4. Whisper
5. Indian Voice
 Please choose 1,2,3,4 or 5
5
Traceback (most recent call last):
  File "speak.py", line 16, in <module>
    os.system("say -v sangeeta $s" % speak)
TypeError: not all arguments converted during string formatting

Пожалуйста, помогите мне. Я молод и мне нужна помощь. Будет только голосовать вниз, если вы не пытаетесь ответить.

1 Ответ

8 голосов
/ 01 октября 2011

Вы ставите знак доллара вместо знака процента:

os.system("say -v sangeeta $s" % speak)

Это должно быть:

os.system("say -v sangeeta %s" % speak)
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...