Practice Problems for loops (DS310323) # others can also try

Problem -1

Calculate the cube of all numbers from 1 to a given number

Write a program to rint the cube of all numbers from 1 to a given number

Given:

input_number = 6

Expected output:

Current Number is : 1 and the cube is 1
Current Number is : 2 and the cube is 8
Current Number is : 3 and the cube is 27
Current Number is : 4 and the cube is 64
Current Number is : 5 and the cube is 125
Current Number is : 6 and the cube is 216

Problem - 2 Display numbers from -10 to -1 using for loop
Expected output:

-10
-9
-8
-7
-6
-5
-4
-3
-2
-1

HINTS:- 1

List item

*Iterate numbers from 1 to n using for loop and range() function

  • In each iteration of a loop, calculate the cube of a current number (i) by multiplying itself three times (c = i * i* i)

Each and every batch can solve this problem and share your code with your friends :upside_down_face:

Regards
Utkarsh Kesharwani

2 Likes

i = int(input("Enter the limit of the range: "))

for num in range(1, i+1):
cube = num ** 3
print(“Cube of”, num, “is”, cube)

1 Like

Q 2

for i in range(-10, 0):
print(i)

1 Like

Problem 1:
i=1

while i<=6:
print(“Current number is:”,i,“and the cube is:”, i * i * i )
i=i+1

Problem 2:
i=-10

while i<=-1:
print(i)
i=i+1

NOTE: It does not reflect space after while loop .

1 Like

Problem 1:

num=int(input(“input_number:”))
for i in range(1,num+1):
print(“Current Number is:”,i,“and the cube is”,i**3)

Problem 2:

for i in range(-10,0):
print(i)

for i in range(1,7):
print(“Current Number is:”, i , “and”, “the cube is” , i**3)

for num in range(-10,0):
print(num)

Problem 1
=>while loop
i=1
while i<=6:
print(i,“^”,3,“=”,i**3)
i=i+1

Problem2
for i in range (-10,0)
print(i)

for problem 1:

i=1
while i<=6:
cube=i**3
print(“Current number is:”,i,“and the cube is”,cube)
i+=1

For problem 2:

for i in range(-10, 0):
print(i)

for i in range(7):
print(“Current Number is:”,i,“and the cube is:”,i**3)

num=6
while num<=6
print(num,“^ 3=”,num**3)
num=num+1

Komal

num=1
while num<=6:
print(num,“^”,3.“=”,num**3)

Problem 1:

num=int(input(“input_number:”))
for i in range(1,num+1):
print(“Current Number is:”,i,“and the cube is”,i**3)

Problem 2:

for i in range(-10,0)
print(i)

Komal

Problem 2

for i in range(-10,0):
print(i)

problem no.1

num=1
while num<=6:
print(num,“^”,3,“=”,num**3)
num=num+1

Problem -1 Cube of Number

n=int(input("enter the number range "))

for i in range(1,n):
print(“Current number is :”, i ,“and the cube is”,i**3)


Problem-2- Display numbers from -10 to -1 using for loop

for i in range(-10,0) :
print(i)

problem 2

for num in range (-10,0):
print(num)

#Write a program to find the cube of all numbers from 1 to a given number
num=int(input(“Enter the number”))
for i in range(1,num+1):
print(“Current Number is :” ,i, "and the cube is ",i**3)

#Display numbers from -10 to -1 using for loop
num=-10
while num<=-1:
print(num)
num+=1

1 Like

i=1

while i<=6:
print(“Current number is:”,i,“and the cube is:”, i * i * i )
i=i+1

Problem 2:
i=-10

while i<=-1:
print(i)
i=i+1

1 Like

welcome to community @almasafrudheen

problem-1
ans- https://colab.research.google.com/drive/1SlZ82p9YVxhYGPk1h5g_vbAb29l3igsZ#scrollTo=4ty1bRMPH5Zk&line=3&uniqifier=1

1 Like