zoukankan      html  css  js  c++  java
  • 初学python(print使用、条件分支、循环、模块引用)

     1 import random
     2 
     3 """
     4 #查看源代码日后爬虫用
     5 import urllib.request
     6 
     7 # coding=utf-8
     8 
     9 url = "http://www.baidu.com"
    10 data = urllib.request.urlopen(url).read()
    11 data = data.decode('UTF-8')
    12 
    13 print(data)
    14 
    15 # print练手
    16 x = 5 / 2
    17 y = 3 / 2
    18 
    19 print('x为', x, '
    ', 'y为', y)
    20 print('x和y分别为%.1f,%.1f' % (x, y))
    21 
    22 for z in range(1, 11):
    23     print('{0:5d} {1:5d} {2:4d}'.format(z, z * z, z * z * z))
    24 
    25 print("what? ?" + " water")
    26 print(5 + 8)
    27 """
    28 # if else语句练手
    29 
    30 
    31 Help = '大了'
    32 Help2 = '小了'
    33 gmAnswer = 12450
    34 key = random.randint(1, 10)
    35 gmAnswer = key
    36 life = 3
    37 
    38 while life > 0:
    39     userAnswer = int(input('随便给个整数'))  # 直接将输入的str转换成int并赋值
    40     if userAnswer < gmAnswer:
    41         print(Help2)
    42     elif userAnswer > gmAnswer:
    43         print(Help)
    44     else:
    45         print('you win')
    46         break
    47     life -= 1
  • 相关阅读:
    ABAP-smartforms
    字符串截取,长度获取
    ',' 导致excel 分列显示
    SALV使用
    SALV双击事件,相应另一个SALV
    CLEAR REFRESH区别
    SY-INDEX和SY-TABIX区别
    JIT机制对运行速度的优化
    《大道至简》读后感
    N皇后问题
  • 原文地址:https://www.cnblogs.com/yosha/p/6129263.html
Copyright © 2011-2022 走看看