TypeError: 在字符串格式化过程中并非所有参数都被转换是什么意思?

发布于 2024-12-07 05:54:03 字数 2917 浏览 0 评论 0原文

这是我的第一个程序,它基本上以不同的声音大声说出内容:

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

请帮助我。我还年轻,需要一些帮助。如果您不想回答,只会投反对票。

here is my first program it basically says stuff out loud and in different voices :

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")

and this is the error:

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

Please help me. I am young and need some help. Will only down vote if you aren't trying to answer.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

还如梦归 2024-12-14 05:54:03

您输入美元符号而不是百分号:

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

这应该是:

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

You put a dollar sign instead of a percent sign:

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

This should be:

os.system("say -v sangeeta %s" % speak)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文