jetbrains : coffee machine stage 5 problem

list function :

  • that is, a kind of object where you can get its elements one by one.
  • iterable : string ,but integer is non-iterable
  • empty lists
  • len()
list_out_of_string = list('danger!')
print(list_out_of_string)  # ['d', 'a', 'n', 'g', 'e', 'r', '!']
 
list_out_of_integer = list(235)  # TypeError: 'int' object is not iterable
numbers = [1, 2, 3, 4, 5]
print(len(numbers))  # 5
 
empty_list = list()
print(len(empty_list))  # 0
 
single_element_list = ['danger!']
print(len(single_element_list))  # 1
 
multi_elements_list = list('danger!')
print(len(multi_elements_list))  # 7
empty_list_1 = list()
print(empty_list_1)

or 
print(list())
name = ['Helen']
print(name)

loop

k = int(input())

total = 0
for i in range(1, k + 1):
    total += i
print(total)
oceans = ['Atlantic', 'Pacific', 'Indian', 'Southern', 'Arctic']
for ocean in oceans:
    print(ocean)


result :

Atlantic
Pacific
Indian
Southern
Arctic
for char in 'magic':
    print(char)
m
a
g
i
c
times = int(input('How many times should I say "Hello"?'))
for i in range(times):
    print('Hello!')

range

Let's look at the example below:

for i in range(5):
    print(i)
What we'll get is this:

0
1
2
3
4
You can change the starting value if you’re not satisfied with 0, moreover, you can configure the increment (step) value by adding a third parameter:

for i in range(5, 45, 10):
    print(i)
According to the parameters included, we’ve asked to print the numbers from 5 to 45 with an increment value of 10. Be careful again, the last value is not included in the output:

5
15
25
35
names = ['Rose', 'Daniel']
surnames = ['Miller']
for name in names:
    for surname in surnames:
         print(name, surname)


Rose Miller
Daniel Miller

在这里插入图片描述

digits = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"]
for i in input():
    print(digits[int(i)])

在这里插入图片描述

a = input()
word = ""
for i in a:
    if  i.islower():
        word += i
    elif i.isupper():
        word += i.replace(i, '_' + i.lower())
print(word)

how to reverse string?

  • str=“Python”
    reversedstring=’’.join(reversed(str))

  • word = input()
    if word == word[::-1]:
    print(“Palindrome”)
    else:
    print(“Not palindrome”)

在这里插入图片描述

while True:   
 nums = int(input())
 if nums < 10:
     continue
 elif nums > 100:
     break
 print(nums)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值