Untitled

mail@pastecode.io avatar
unknown
plain_text
22 days ago
1.3 kB
2
Indexable
Never
# paste Homework
def sum(num1,num2)
    print(num1+num2)

sum(1,2)    

#for loop
for i in range (5):
    print("hello python")

#for loop     
for i in range (2,-3,-1):
    print(i)


#while loop
i = 0
while i<5 :
    i= i+1 
    print('Hello loops')

# 0 false 
# 1 True



## 'Nested Loop' 
# THIS CODE PRINTING 'numbers' 5*3 Times
i =0 
# i=0
while i<5:
# 1< 5    
     for t in range (3):
# t=0 0<3 t=1 1<3 t=2 2<3   
      print()
     i=i+1 
    

# i =0    i=1    i=2    i=3    i=4    i= 5
# 0 1 2   0 1 2  0 1 2  0 1 2  0 1 2  0 1 2 



# Fight Game Code 
from mblock import event

import time
wait_time=0.03
@event.greenflag
def on_greenflag():
    sprite.set_costume('Idle')
    sprite.set_variable('P1Health', 100)

    while True:
        if sprite.is_keypressed('right arrow'):
         move(10)
        if sprite.is_keypressed('left arrow'):
         move(-10)

def move(direction):
    sprite.change_x_by(direction)
    sprite.set_costume('Walk1')
    time.sleep(wait_time)
    sprite.set_costume('walk2')
    time.sleep(wait_time)
    sprite.set_costume('walk3')
    time.sleep(wait_time)
    sprite.set_costume('Idle')


# HomeWork
 Create Loop to print numbers from 11 to 20 using for loop (in python )
Leave a Comment