zoukankan      html  css  js  c++  java
  • python学习4——提问、提示。

    一、提问——打印出改变了的输出。

    因为没有任何计算机基础,所以出错很多,摸索了一会。

    出错1:

    print("How old are you?"),
    age = raw_input()
    print("What is your name?"),
    name = raw_input()
    print("How tall are you?"),
    height = raw_input()
    print("So your name is %r, you are %r years old and %r tall." , %name,age,height)

     输出结果

    E:abc>python 6.py
    How old are you?
    Traceback (most recent call last):
    File "6.py", line 2, in <module>
    age = raw_input()
    NameError: name 'raw_input' is not defined

    原因:python3中将raw_input()命令改为input(),所以不能会有未定义错误。

    出错2:

    print("How old are you?"),
    age = input()
    print("What is your name?"),
    name = input()
    print("How tall are you?"),
    height = input()
    print("So your name is %r, you are %r years old and %r tall." , %name,age,height)

    输出结果

    E:abc>python 6.py
    File "6.py", line 7
    print("So your name is %r, you are %r years old and %r tall.", %name,age,height)

    ^
    SyntaxError: invalid syntax

    原因:

    %符号前面不应该有:逗号

    出错3:

    print("How old are you?"),
    age = input()
    print("What is your name?"),
    name = input()
    print("How tall are you?"),
    height = input()
    print("So your name is %r, you are %r years old and %r tall."  %name,age,height)

    输出结果

    E:abc>python 6.py
    How old are you?
    20
    What is your name?
    jack
    How tall are you?
    189
    Traceback (most recent call last):
    File "6.py", line 7, in <module>
    print("So your name is %r, you are %r years old and %r tall." %name,age,height)
    TypeError: not enough arguments for format string

    原因:

    % 后定义的变量需要用()引用

    最终正确的代码如下:

    print("How old are you?"),
    age = input()
    print("What is your name?"),
    name = input()
    print("How tall are you?"),
    height = input()
    print("So your name is %r, you are %r years old and %r tall." %(name,age,height))

    输出结果:

    E:abc>python 6.py
    How old are you?
    18
    What is your name?
    lucy
    How tall are you?
    168
    So your name is 'lucy', you are '18' years old and '168' tall.

    二、提示

    age = input("How old are you?")
    name = input("What is your name?")
    weight = input("How much do you weight?")
    print("So your name is %r, you are %r years old and %r tall." %(name,age,weight))

     三、python -m pydoc input 查看命令。

    通过cmd输入python -m pydoc input 可以查看各命令的解释。

    如查看 sys 命令:

  • 相关阅读:
    keras----resnet-vgg-xception-inception
    ubuntu16.04----jdk---install----config
    ubuntu16.04--在标题栏显示网速
    caffe学习--cifar10学习-ubuntu16.04-gtx650tiboost--1g--03--20171103
    matlab2016b-linux版本在ubutu16.04x64上面不能打开摄像头的处理方法
    eclipse adt开发android ndk没有NDK选项问题的解决方案
    Failed to fetch URL https://dl-ssl.google.com/android/repository/addons_list-2.xml, reason: Connect
    eclipse--windowBuilder
    qt-mingw530-opencv-开发配置
    蔽月山房---作者,王阳明
  • 原文地址:https://www.cnblogs.com/shannon-V/p/9506470.html
Copyright © 2011-2022 走看看