码迷,mamicode.com
首页 > 其他好文 > 详细

if-for-while语句

时间:2017-12-23 01:11:21      阅读:237      评论:0      收藏:0      [点我收藏+]

标签:process   ==   ini   keep   with   must   roc   wan   sse   

def print_paras(fpara, *nums, **words):
    print("fpara: " + str(fpara))
    print("nums: " + str(nums))
    print("words: " + str(words))


print_paras("hello", 1, 3, 5, 7, word="python", anohter_word="java")
# fpara: hello
# nums: (1, 3, 5, 7)
# words: {‘word‘: ‘python‘, ‘anohter_word‘: ‘java‘}
# Process finished with exit code 0
# if语句
number = 59
guess = int(input(‘Enter an integer:‘))
if guess == number:
    print(‘guess right‘)
elif guess < number:
    print(‘too small‘)
else:
    print(‘lower‘)
# for 语句
for i in range(1,10):
    print(i)
else:
    print(‘over‘)

a_list = [1,3,5,7,9]
for i in a_list:
    print(i)

a_tuple = (1,3,5,7)
for i in a_tuple:
    print(i)

a_dict = {‘Tom‘:‘111‘,‘jerry‘:‘222‘,‘catty‘:‘333‘}
for ele in a_dict:
    print(ele)
    print(a_dict[ele])
for key,elem in a_dict.items():
    print(key,elem)
# catty
# 333
# jerry
# 222
# Tom
# 111
# catty 333
# jerry 222
# Tom 111

  

number = 59
guess_flag = False
while guess_flag == False:
    guess = int(input(‘Enter an integer : ‘))
    if guess == number:
        # New block starts here
        guess_flag = True

        # New block ends here
    elif guess < number:
        # Another block
        print(‘No, the number is higher than that, keep guessing‘)
        # You can do whatever you want in a block ...
    else:
        print(‘No, the number is a  lower than that, keep guessing‘)
        # you must have guessed > number to reach here

print(‘Bingo! you guessed it right.‘)
print(‘(but you do not win any prizes!)‘)
print(‘Done‘)

  

# Enter an integer : 5
# No, the number is higher than that, keep guessing
# Enter an integer : 59
# Bingo! you guessed it right.
# (but you do not win any prizes!)
# Done

if-for-while语句

标签:process   ==   ini   keep   with   must   roc   wan   sse   

原文地址:http://www.cnblogs.com/zlz-leidaxia/p/8088051.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!