• 代码,python1


     1 def main():
     2     try:
     3         number1,number2=eval(input("please enter two number"))
     4         result=number1/number2
     5     except ZeroDivisionError:
     6         print("the division is 0",result)
     7     except SyntaxError:
     8         print("syntax is wrong")
     9     else:
    10         print("ok the result is ",result)
    11     finally:
    12                              print("i don't know")
    13 main()

     

     1 Python 3.6.1rc1 (v3.6.1rc1^0:e0fbe5feee4f9c00f09eb9659c2182183036261a, Mar  4 2017, 20:00:12) [MSC v.1900 64 bit (AMD64)] on win32
     2 Type "copyright", "credits" or "license()" for more information.
     3 >>> 
     4 = RESTART: C:/Users/lenovo/AppData/Local/Programs/Python/Python36/pytho2.py =
     5 please enter two number1 3
     6 syntax is wrong
     7 i don't know
     8 >>> main()
     9 please enter two number1,2
    10 ok the result is  0.5
    11 i don't know
    12 >>> main()
    13 please enter two number
    14 syntax is wrong
    15 i don't know
    16 >>> main()
    17 please enter two number1,0
    18 i don't know
    19 Traceback (most recent call last):
    20   File "C:/Users/lenovo/AppData/Local/Programs/Python/Python36/pytho2.py", line 4, in main
    21     result=number1/number2
    22 ZeroDivisionError: division by zero
    23 
    24 During handling of the above exception, another exception occurred:
    25 
    26 Traceback (most recent call last):
    27   File "<pyshell#3>", line 1, in <module>
    28     main()
    29   File "C:/Users/lenovo/AppData/Local/Programs/Python/Python36/pytho2.py", line 6, in main
    30     print("the division is 0",result)
    31 UnboundLocalError: local variable 'result' referenced before assignment
    32 >>> main()
    33 please enter two number1.1,0.0
    34 i don't know
    35 Traceback (most recent call last):
    36   File "C:/Users/lenovo/AppData/Local/Programs/Python/Python36/pytho2.py", line 4, in main
    37     result=number1/number2
    38 ZeroDivisionError: float division by zero
    39 
    40 During handling of the above exception, another exception occurred:
    41 
    42 Traceback (most recent call last):
    43   File "<pyshell#4>", line 1, in <module>
    44     main()
    45   File "C:/Users/lenovo/AppData/Local/Programs/Python/Python36/pytho2.py", line 6, in main
    46     print("the division is 0",result)
    47 UnboundLocalError: local variable 'result' referenced before assignment
    48 >>> 
    49 = RESTART: C:/Users/lenovo/AppData/Local/Programs/Python/Python36/pytho2.py =
    50 please enter two number
    51 1,1
    52 ok the result is  1.0
    53 i don't know
    54 >>> python2.py
    55 Traceback (most recent call last):
    56   File "<pyshell#5>", line 1, in <module>
    57     python2.py
    58 NameError: name 'python2' is not defined
    59 >>> pytho2.py
    60 Traceback (most recent call last):
    61   File "<pyshell#6>", line 1, in <module>
    62     pytho2.py
    63 NameError: name 'pytho2' is not defined
    64 >>> main
    65 <function main at 0x0000013B8E633E18>
    66 >>> main()
    67 please enter two number
    68 1.1,0.0
    69 i don't know
    70 Traceback (most recent call last):
    71   File "C:/Users/lenovo/AppData/Local/Programs/Python/Python36/pytho2.py", line 4, in main
    72     result=number1/number2
    73 ZeroDivisionError: float division by zero
    74 
    75 During handling of the above exception, another exception occurred:
    76 
    77 Traceback (most recent call last):
    78   File "<pyshell#8>", line 1, in <module>
    79     main()
    80   File "C:/Users/lenovo/AppData/Local/Programs/Python/Python36/pytho2.py", line 6, in main
    81     print("the division is 0")
    82 UnboundLocalError: local variable 'result' referenced before assignment
    83 >>> 
    84 = RESTART: C:/Users/lenovo/AppData/Local/Programs/Python/Python36/pytho2.py =
    85 please enter two number
    86 1,0
    87 the division is 0
    88 i don't know
    89 >>> 

     2.

     1 def root():
     2     try:
     3         print("please enter threes numbers:
    ")
     4         a,b,c=input("yes please such as(z,x,y)")
     5         discRoot=math.sqrt(b*b-4*a*c)
     6         root1=(-b+discRoot)/(2*a)
     7         root2=(-b-discRoot)/(2*a)
     8         print("the root is",root1,root2)
     9     except ValueError:
    10         print("
     no really root)
    11 root()

    冒号忘了,还有:eval()

    修后如下:

     1 import math
     2 def main1():
     3     try:
     4         number1,number2=eval(input("please enter two number
    "))
     5         result=number1/number2
     6     #except ZeroDivisionError:
     7      #   print("the division is 0")
     8     except ZeroDivisionError:
     9         print("the division is 0")
    10     except SyntaxError:
    11         print("syntax is wrong")
    12     else:
    13         print("ok the result is ",result)
    14     finally:
    15                              print("i don't know")
    16 
    17 def root():
    18     try:
    19         print("please enter threes numbers:
    ")
    20         a,b,c=eval(input("yes please such as(z,x,y):"))
    21         print("www")
    22         discRoot=math.sqrt(b * b - 4 * a * c)
    23         print("hey here")
    24         root1=(-b+discRoot)/(2*a)
    25         root2=(-b-discRoot)/(2*a)
    26         print("the root is",root1,root2)
    27     except ValueError:
    28         print("
     no really root")
    29 root()
    30         
  • 相关阅读:
    【乱侃】How do they look them ?
    【softeware】Messy code,some bug of Youdao notebook in EN win7
    【随谈】designing the login page of our project
    【web】Ad in security code, making good use of resource
    SQL数据库内存设置篇
    关系数据库的查询优化策略
    利用SQL未公开的存储过程实现分页
    sql语句总结
    sql中使用cmd命令注销登录用户
    SQLServer 分页存储过程
  • 原文地址:https://www.cnblogs.com/pppjjjccc/p/6690479.html
Copyright © 2020-2023  润新知