-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction.py
More file actions
131 lines (103 loc) · 2.67 KB
/
Copy pathfunction.py
File metadata and controls
131 lines (103 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# ##13th april
# #user defined function
# def greeting(): # defining of a function
# print("hello good morning !!")
# greeting() ## --> calling of a function
# greeting() ## --> calling of a function
# greeting() ##--> calling of a function
# greeting() ##--> calling of a function
# ##parameters and arguments
# def addition(a,b): ## a and b are parameter
# print(a + b)
# addition(10,20)
# ## palindrome
# def palindrome(n): # a and b are palindrome
# copy = n
# rev = 0
# while n != 0:
# rev = rev*10+n%10
# n = n//10
# if rev == copy:
# print("entered number is palindrome")
# else:
# print("entered number is not a palindrome")
# palindrome(121)
# palindrome(123)
# palindrome(1234)
# palindrome(4444)
# #1st positional argument
# def multiply(a,b):
# print(a *b)
# multiply(12,67)
# ##2nd default argument/keyword argument
# #def info (name,age):
# def info(a,b,c,d,e):
# print(a,b,c,d,e)
# #print(f"your name is {name} and your age is {age}")
# #info(age = 24,name = "harsh")
# info (12,34,e = 67 ,c = 12 , d = 67)
# ## if you give a value using default argument you always have to give further value using default argument
# ##default parameter
# def info(name,age,id =None ):
# print("info recieved")
# info("Deepak",24,1234)
# # return vs print
# def hello():
# return "how are you"
# #a = hello()
# #print(a)
# print(hello())
# ##
# def agechecker(n):
# if n >= 18:
# return True
# else:
# return False
# age = int(input("tell your age :-"))
# if agechecker(age):
# print("you can vote")
# else:
# print("you cannot vote")
# ###
# def hello1():
# hello2()
# print("hello1")
# def hello2():
# hello3()
# print("hello2")
# def hello3():
# hello4()
# print("hello3")
# def hello4():
# print("hello4")
# hello1()
# ## print 1 to n using function
# def numbers(n):
# if n == 1001:
# return "done"
# print(n)
# numbers(n+1)
# numbers(1)
# ## reverse / backtracking
# def numbers(n):
# if n == 1001:
# return "done"
# numbers(n+2)
# print(n)
# numbers(1)
## 7 Reverse a number using function
def reverse_numbers(n,rev = 0):
if n == 0:
return rev
else:
return reverse_numbers(n//10, rev*10 + n%10)
num = int(input("enter your number"))
print("reversed number", reverse_numbers(num))
# def reverse_number(n, rev=0):
# if n == 0:
# return rev
# else:
# return reverse_number(n // 10, rev * 10 + n % 10)
# # input
# num = int(input("Enter a number: "))
# print("Reverse =", reverse_number(num))