if-for-while语句

Posted 雷大侠!

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了if-for-while语句相关的知识,希望对你有一定的参考价值。

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语句的主要内容,如果未能解决你的问题,请参考以下文章

SQL Select 语句的用法

[AndroidStudio]_[初级]_[配置自动完成的代码片段]

[AndroidStudio]_[初级]_[配置自动完成的代码片段]

[AndroidStudio]_[初级]_[配置自动完成的代码片段]

20个简洁的 JS 代码片段

20个简洁的 JS 代码片段