Loop

“for” loop 是重复行为很多次. “while” loop 是一直循环直到达到某个要求

For loop:
Vo =[10,11,12,13,14,15,16,17,18,19,20]
hmax = []
tmax = []
g = 9.8
ho = 1.75
#tmax = vo/g = i/g
for i in Vo:
hmax.append(ho+i*i/g-(1/2)g(i/g)**2)
for i in Vo:
tmax.append(i/g)

While loop:
t=[]
x=0
while t<10.5
t.append(x)
x+=0.5
print(t) 先定义一个t空集,然后写个x起始值,然后while t直到10.5,然后t里加入x list,x为每次增加0.5. 所以x+=0.5
EXAMPLE:
ho=1.75
g=9.8
vo=47
t=0
hmax=0
tmax=0
hold=ho
while t < 10.5:
t+=0.5
h = ho+vot-0.5g*t**2
if h > hmax:
hmax=h
tmax=t

if h<hold:
    print("the snowball is falling at",t)
hold=h

print(hmax)
print(tmax)

IF:
some_numbers = [2, -5, 16, 17, -6, 23, 0]

for i in range(len(some_numbers)):
number = float(some_numbers[i])
if number < 0:
print(‘Square root is not real.’)
else:
print(‘Square root of {} is {:.4f}’.format(number, number**(1/2)))
# What going on with all the {}'s and the “format” bits above?

for number in some_numbers:
if number > 0:
print(‘The number is positive.’)
elif number < 0:
print(‘The number is negative.’)
else:
print(‘The number is zero.’)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值