-
Notifications
You must be signed in to change notification settings - Fork 0
/
Q09.py
63 lines (42 loc) · 1.32 KB
/
Q09.py
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
"""
Aledutron
SPPU 2019 FE PPS Lab
SPPU First Year (FE) Programming and Problem Solving (PPS) Lab Assignments (2019 Pattern)
Youtube PPS Playlist Link: https://youtube.com/playlist?list=PLlShVH4JA0osTzddxh-2s1yaigpyp6DRx&si=5RWSN_MmtX1FACb1
Problem Statement:
Q9
To accept a number from user and print digits of number in a reverse order.
Explaination Video Link: https://www.youtube.com/watch?v=t9YRuegvDBM&list=PLlShVH4JA0osTzddxh-2s1yaigpyp6DRx&index=10&pp=iAQB
"""
# Method 1 - Strings
# number = input("Enter a number: ")
# -3 -2 -1
# 234 = 432 ->
# 012
# 023 --> 23 -> 32
# for i in range(len(number)-1,-1,-1):
# print(number[i],end="")
# for i in range(1,len(number)+1):
# print("i is ",-i)
# print(number[-i])
# number = number[::-1] #a-starting index(0) , b-ending index(last index), c-step(1)
# print(number)
# revnum = ''
# for i in number:
# revnum = i + revnum # revnum = '2' + '' -> '2'
# # revenum = '3' + '2' -> '32'
# # revenum = '4' + '32' -> '432'
# print(revnum)
# Method 2 - Int
# number = int(input("Enter a number: "))
# numofdigit = len(str(number))
# 234 - 4 3 2
# 23 - quotient (// floor division)
# 10 | 234
# -230
# 4 - remainder (% modulus)
# revernum = ""
# for i in range(numofdigit):
# revernum += str(number % 10)
# number = number // 10
# print(revernum)