Exercise 1 solution : Python tutorial 121

preview_player
Показать описание
Guys please help this channel to reach 20,000 subscribers. I'll keep uploading quality content for you.

Python is easy programming language to learn and anyone can learn it, and these tutorials are 100% free in hindi.

You can share this playlist with your brother, sisters and friends. This will surely add some values to their life.

If you follow this complete playlist of python tutorial surely you will learn everything about python programming language.

This is solution of exercise 1 of chapter 7

Рекомендации по теме
Комментарии
Автор

user = {}
n = int(input("Enter the number"))
for i in range(1, n+1):
user.update({i:i**3})
print(user)

rajeshprajapati
Автор

def cube(n):
cubesDict = {}
for i in range (1, n+1):
cubesDict.update({i:i*i*i})
return cubesDict;

muzik
Автор

1. Using while loop
num = int(input("enter a number: "))
num_cube = {}
i = 0
def cube_num(n):
i=1
while i<=num:
num_cube[i]=i**3
i+=1
return num_cube
print(cube_num(num))



2. Using for loop

num = int(input("enter a number: "))
numb_cube = {}
def cube_num(n):
for i in range(1, num+1):
numb_cube[i] = i**3
return numb_cube
print(cube_num(num))

chhiningmagar
Автор

#cube finder
def cube_finder(n):
cubes={}
for i in range(1, n+1):
cubes[i]=i**3
pass
return cubes


print(cube_finder(5))

sagarbhagat
Автор

def cube(n):
a=dict.fromkeys(range(1, n+1), 1)
for i in a:
b={i:i**3}
a.update(b)
return a
print(cube(3))#{1:1, 2:8, 3:27}

Saikiran-tymo
Автор

my solution:

def cube_finder(n):
cube = {}
for i in range(1, n+1):
cube[i] = i**3
return cube

print(cube_finder(4))

prabhatnagdeve
Автор

I did like this: -


Number = 5
def Cube_Finder(N):
Cubed = {

}
i = 1
while i <= N:
Cubed[i] = i*i*i
i += 1
return Cubed
print(Cube_Finder(Number))

Dudeinfire
Автор

MY CODE:



def cube_finder(n):
_dict = {}
for i in range(1, n+1):
_dict.update({i : i **3})
return _dict
print(cube_finder(3))


OUTPUT: 1:1, 2: 8, 3:27

hackerkhan
Автор

maine fromkeys use kiya..
def cube_finder(n):
dic = {}
for i in range(1, n+1):
dic = dict.fromkeys(i, i**2)
return dic
print(cube_finder(5))

trigger
Автор

check This pls..
n=int(input("Enter a no: "))
def cube_finder(n):
d={}
for i in range(1, n+1):
d1=dict.fromkeys([i], i**3)
d.update(d1)
return d
print(cube_finder(n))

kripamoypatra
Автор

def func(n):
d={}
for i in n:
d[i]=i**3
return d

n={1, 2, 3, 4, 5, 6, 7, 8, 9}
print(f"your key cube is{func(n)}")

masterdon
Автор

is this correct, i am getting same output

def cube(n):
num_cube = {}
for i in range(1, n+1):
j = i**3
more_info = {i :j}
num_cube.update(more_info)
return num_cube

amithsuryan
Автор

def cubeteller(n):
Dict={}
for i in range(1, n+1):
Dict.update({i:i*i*i})
return Dict

chaitanyaubale
Автор

Take a minute to thank Harshit for providing & teaching "premium" content for free❤️
Thank you for this❤️

shaguntripathi
Автор

Good but not able to understand how cubes[I] is returning in the form of a dictionary.

vishnujatav
Автор

def cubedict(n):
retdict = {}
for i in range(1, n+1):
temptup = {i : i**3}
retdict.update(temptup)
return retdict

print(cubedict(50))

harikadas
Автор

bhai yeh error aa rha h UnboundLocalError: local variable 'i' referenced before assignment

vishal
Автор

num = int(input("Enter number"))
cube = {}
def cubes(a):
for b in range(1, 1+a):
cube[b] = b*b*b
return cube
print(cubes(num))

teach-with-noor
Автор

n=int(input("enter the number "))
def cube_finder(l):

cube_f={}
cube={}
i=1
while i<l or i==l:
cube[i]=i**3
cube_f.update(cube)
i=i+1
return cube_f
print(cube_finder(n))

pratikchaudhari
Автор

why every time it seems so easy, when you do it ;)

CmonRishi