我不断收到关于我应该做什么和我实际做了什么的错误信息 [英] I keep getting error messages regarding what I'm supposed to do vs what I have actually done

查看:92
本文介绍了我不断收到关于我应该做什么和我实际做了什么的错误信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#INSTRUCTIONS



#在这个程序中,你必须问用户:

#你的名字是什么? br />


#然后打印出个性化的问候语。





#一般规则



#对于名叫Maria的人,请回复打印:

#Hello Maria :)



#对于一个名叫Wally的人,请回复打印:

#Hello Wally :)



#...等。



#一般情况下,对于名为< name>的人,请通过打印回复:

#Hello< name>





#特别名称



#两个人很特别:Amar和Brandy。

#一个名叫Amar或Brandy的人在你打招呼之后应该收到一条额外的评论



#对于一个名叫Amar的人,回复者说:

#Hello Amar :)

#我喜欢你的鞋子



#对于一个名叫的人白兰地,回应说:

#Hello Brandy :)

#你好像很酷的人





#请注意,如果您的

#打印语句与上面指定的完全匹配,机器人评分员只会标记您的解决方案。



#拼写,间距,标点符号......所有这些都很重要。



#您的输入声明也很重要。你必须这样说:

#你叫什么名字?





#--- -------------------------------------------------- ---------------





#将你的Python代码放在​​这里:



我尝试过:



 name =输入( 你叫什么名字?
print Hello,name + :)

if name == ' Amar'
print 我喜欢你的鞋子
elif name == ' Brandy'
print 你好像很酷

解决方案

这很有意思。当我在Windows命令提示符下测试你的代码时,你的脚本失败了:

 name = input( 你叫什么名字?
print Hello,name + : )
如果 name == ' Amar'
print 我喜欢你的鞋子
elif name == ' Brandy'
print 你好像很酷





命令和结果:

#windows 
>回声白兰地| python hello.py
你叫什么名字? Hello Brandy:)





但它在linux上成功运行:

 


echo Brandy | python3.6 hello.py
你叫什么名字?你好白兰地:)
你好像很酷的人





Windows中的原因也包含新行;在linux中它没有。



解决方案:

 name = input( 你叫什么名字?
name = name.strip()
print Hello,name + :)
如果 name == ' Amar'
print 我喜欢你的鞋子
elif name == ' Brandy'
print 你好像很酷


# INSTRUCTIONS
#
# In this program, you must ask the user:
# "What is your name?"
#
# And then respond by printing out a personalized greeting.


# GENERAL RULE
#
# For a person named Maria, respond by printing:
# Hello Maria :)
#
# For a person named Wally, respond by printing:
# Hello Wally :)
#
# ...etc.
#
# In general, for a person named <name>, respond by printing:
# Hello <name>


# SPECIAL NAMES
#
# Two people are special: Amar and Brandy.
# A person named Amar or Brandy should receive an additional comment after you say hello
#
# For a person named Amar, respond by saying:
# Hello Amar :)
# I like your shoes
#
# For a person named Brandy, respond by saying:
# Hello Brandy :)
# You seem like a cool person


# Note that the robot grader will only mark your solution correct if your
# print statements match EXACTLY what was specified above.
#
# Spelling, spacing, punctuation... all that stuff matters.
#
# Your input statement also matters. You must say it exactly like this:
# What is your name?


# --------------------------------------------------------------------


# Put your Python code here:

What I have tried:

name = input("What is your name? ")
print("Hello",name+" :)")

if name == 'Amar':
  print ("I like your shoes")
elif name == 'Brandy':
    print ("You seem like a cool person")

解决方案

This is kind of interesting. When I tested your code in windows command prompt it failed with your script:

name = input("What is your name? ")
print("Hello",name+" :)")
if name == 'Amar':
  print ("I like your shoes")
elif name == 'Brandy':
    print ("You seem like a cool person")



Command and Result:

# windows
> echo Brandy | python hello.py
What is your name? Hello Brandy  :)



But it successfully ran on linux:


echo Brandy | python3.6 hello.py What is your name? Hello Brandy :) You seem like a cool person



Reason is in windows name also contains new line; in linux it does not.

Solution:

name = input("What is your name? ")
name = name.strip()
print("Hello",name+" :)")
if name == 'Amar':
  print ("I like your shoes")
elif name == 'Brandy':
    print ("You seem like a cool person")


这篇关于我不断收到关于我应该做什么和我实际做了什么的错误信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆