Discuss / Python / 交作业2015.7.2

交作业2015.7.2

Topic source

Gussun

#1 Created at ... [Delete] [Delete and Lock User]

Notepad快捷键: 群组注释 Ctrl+Shift+Q 取消群组注释 Ctrl+Shift+K

# -*- coding: utf-8 -*-

#循环的练习题
#使用for循环完成
L = ['Bart', 'Lisa', 'Adam']
for name in L:
    print('Hello,',name,'!')

#使用while循环完成    
i=0
x=len(L)
while i<x: 
    print('Hello,',L[i],'!')
    i=i+1

三片子

#2 Created at ... [Delete] [Delete and Lock User]

感谢while 语句上给的提示,没想到

#!/usr/bin/env python3
# -*- coding: utf-8 -*-



n1=input('please enter your name:')
n2=input('please enter your frend1\'s name:')
n3=input('please enter your frend2\'s name:')
names = [n1,n2,n3]
num=(len(names))
n=0
while n < num:
  print('Hello',names[n],'!')
  n=n+

  • 1

Reply