In this tutorial, we will learn how to find the factorial of a given number using Python program?
# square of number def square (number) : return number*number # cube of a number def cube (number) : return number** 3 # nth power of a number def nth_power (number,power) : return number**power # sum of n numbers def sum_of_n_numbers (number) : return number*(number+ 1 )/...
Python | Write functions to find square and cube of a given number. Python | 编写函数以查找给定数字的平方和立方。 Python program to find the power of a number using loop Python程序使用循环查找数字的幂 Python program to find the power of a number using recursion Python程序使用递归查找数字的幂...
price in products: # A if price not in unique_price_list: #B unique_price_list.append(price) return len(unique_price_list) products = [ (143121312, 100), (432314553, 30), (32421912367, 150), (937153201, 30) ] print('number of unique price is: {}'.format(find_unique_price...
Program to find the sum of the cubes of first N natural number # Python program for sum of the# cubes of first N natural numbers# Getting input from usersN=int(input("Enter value of N: "))# calculating sum of cubesumVal=0foriinrange(1,N+1):sumVal+=(i*i*i)print("Sum of cub...
You can also add new items at the end of the list, by using the append() method (we will see more about methods later):您还可以通过使用AppEnter()方法在列表末尾添加新对象(稍后我们会看到更多的方法):>>> cubes.append(216) # add the cube of 6 cube数列增加到6个对象或元素 >>> ...
# Python code to illustrate cube of a number# showing difference between def() and lambda().def cube(y): return y*y*y lambda_cube = lambda y: y*y*y# using the normally# defined functionprint(cube(5)). # 125# using the lambda functionprint(lambda_cube(5)). # 125 ...
# take input from the user num = int(input("Enter a number: ")) # initialize sum sum = 0 # find the sum of the cube of each digit temp = num while temp > 0: digit = temp % 10 sum += digit ** 3 temp //= 10 # display the result if num == sum: print(num,"is an ...
#4-8立方 print("\n\t 4-8 cube") cube_numbers=[] for value in range(1,11): cube_numbers.append(value**3) print(cube_numbers) #本题采用创建空列表形式 #4-9立方-列表解析 print("\n\t4-9 cube-2") cube_numbers=[value**3 for value in range(1,11)] print(cube_numbers) #本题...
... filter(f,range(2,25)) [5,7,11,13,17,19,23] “map(function,sequence)” 为每一个元素依次调用function(item)并将返回值组成一个链表返回。例 如,以下程序计算立方: defcube(x):returnx*x*x ... map(cube,range(1,11)) [1,8,27,64,1 下载文档 收藏 分享 赏 0您...