菜鸟教程 -- 学的不仅是技术,更是梦想!

Python 基础教程
(追記) (追記ここまで)

Python 练习实例46

Python 100例 Python 100例

题目:求输入数字的平方,如果平方运算后小于 50 则退出。

程序分析:

程序源代码:

实例

#!/usr/bin/python# -*- coding: UTF-8 -*-TRUE = 1FALSE = 0defSQ(x): returnx * xprint('如果输入的数字小于 50,程序将停止运行。')again = 1whileagain: num = int(input('请输入一个数字:'))print('运算结果为: %d' % (SQ(num)))ifSQ(num) >= 50: again = TRUEelse: again = FALSE

以上实例输出结果为:

如果输入的数字小于 50,程序将停止运行。
请输入一个数字:12
运算结果为: 144
请输入一个数字:14
运算结果为: 196
请输入一个数字:1
运算结果为: 1

Python 100例 Python 100例

AI 思考中...

6 篇笔记 写笔记

  1. #0

    叮咚

    a12***[email protected]

    3

    参考解法:

    #!/usr/bin/python
    # -*- coding: UTF-8 -*-
    while(1):
     n=input('请输入一个数字:')
     print '运算结果为: %d' % (n**2)
     if n**2 < 50:
     quit()
     else:
     print '请继续输入'
    

    叮咚

    a12***[email protected]

    9年前 (2017年04月10日)
  2. #0

    啊香魂

    wei***[email protected]

    1

    参考解法:

    #! /usr/local/bin
    # -*- coding:UTF-8 -*-
    #求输入数字的平方,如果平方运算后小于 50 则退出。
    def py_pow( number ):
     if pow(number,2)<50:
     print '平方运算后为%2d' % pow(number,2),'结果小于50,所以退出'
     exit();
     else:
     print '平方运算后为%2d' % pow(number,2),'结果不小于50,所以继续\n'
     number = int(raw_input('请输入一个数字:\n'))
     py_pow(number)
    py_number = int(raw_input('请输入一个数字:\n'))
    py_pow(py_number)
    

    啊香魂

    wei***[email protected]

    9年前 (2017年04月21日)
  3. #0

    等一个人

    252***[email protected]

    1

    参考方法:

    #!/usr/bin/env python3
    # -*- coding: utf-8 -*-
    def power(x):
     if x ** 2 >= 50:
     print('{}的平方为:{},不小于50,继续'.format(x, x ** 2))
     else:
     print('{}的平方为:{},小于50,退出'.format(x, x ** 2))
     quit()
    while True:
     x = int(input('输入数字:'))
     power(x)
    

    等一个人

    252***[email protected]

    9年前 (2017年05月04日)
  4. #0

    yorun

    547***[email protected]

    14

    参考方法:

    #!/usr/bin/python3
    while True:
     x = int(input('input a num :'))
     x *= x
     print('结果为:{}'.format(x))
     if x > 50:
     break
    

    yorun

    547***[email protected]

    9年前 (2017年05月14日)
  5. #0

    iMax4ever

    jia***@foxmail.com

    0

    Python3

    while True:
     a = int(input('Enter a number which squr is lager than 50:'))
     if a * a < 50:
     print('{}^2 = {}\nit does not meet the demand'.format(a, a * a))
     break
     else:
     print('{}^2 = {}'.format(a, a * a))

    iMax4ever

    jia***@foxmail.com

    9年前 (2017年10月08日)
  6. #0

    段祺晟

    475***[email protected]

    2

    python3,lambda 表达式

    # 求输入数字的平方,如果平方运算后小于 50 则退出。
    s = 100
    while s > 50:
     number = int(input('please enter a number'))
     f = lambda x: x*x
     print(f(number))

    段祺晟

    475***[email protected]

    9年前 (2017年12月29日)

点我分享笔记

  • 昵称 (必填)
  • 邮箱 (必填)
  • 引用地址

AltStyle によって変換されたページ (->オリジナル) /