aboutsummaryrefslogtreecommitdiff
path: root/Python/Beginner training/Tasks.py
diff options
context:
space:
mode:
authorSyndamia <kami02882@gmail.com>2019-08-17 17:49:01 +0300
committerSyndamia <kami02882@gmail.com>2019-08-17 17:49:01 +0300
commit62b00e6995b388268aef92876d9682b42b1ad2bb (patch)
treeaac49374d68c53d6a47eee7f011faccda693c831 /Python/Beginner training/Tasks.py
parentdfd68eb97e71ffe1f693526ba3daddd4c9558ce5 (diff)
downloadSelf-learning-62b00e6995b388268aef92876d9682b42b1ad2bb.tar
Self-learning-62b00e6995b388268aef92876d9682b42b1ad2bb.tar.gz
Self-learning-62b00e6995b388268aef92876d9682b42b1ad2bb.zip
Did Happy numbers task (karan/Projects) in Python
Diffstat (limited to 'Python/Beginner training/Tasks.py')
-rw-r--r--Python/Beginner training/Tasks.py41
1 files changed, 40 insertions, 1 deletions
diff --git a/Python/Beginner training/Tasks.py b/Python/Beginner training/Tasks.py
index 3ba4354..5c0bdcb 100644
--- a/Python/Beginner training/Tasks.py
+++ b/Python/Beginner training/Tasks.py
@@ -18,6 +18,7 @@ def Divide():
print(round(p2 * 100 / cycle_n, 2), "%")
print(round(p3 * 100 / cycle_n, 2), "%")
+
def Histogram():
cycle_n = int(input("Type number of numbers that will be typed: "))
p1 = 0; p2 = 0; p3 = 0; p4 = 0; p5 = 0
@@ -42,6 +43,7 @@ def Histogram():
print(round(p4 * 100 / cycle_n, 2), "%")
print(round(p5 * 100 / cycle_n, 2), "%")
+
def NumberMatrix():
size = int(input("Type size of matrix: "))
@@ -56,6 +58,7 @@ def NumberMatrix():
else:
print()
+
def Factoriel():
factoriel_n = int(input("Type times of factoriel: "))
@@ -66,7 +69,43 @@ def Factoriel():
print(final_int)
+def HappyNumber():
+ while True:
+ start = int(input("Type a start number: "))
+
+ try:
+ num = start
+ seen = [num]
+
+ while num != 1:
+
+ temp = 0
+ for c in str(num):
+ temp += math.pow(CharToNum(c), 2)
+ num = int(temp)
+
+ if seen.count(num) > 0: raise()
+ seen.append(num)
+
+ print("{0} is a happy number.".format(start))
+ except:
+ print("{0} isn't a happy number.".format(start))
+
+
+def CharToNum(char):
+ if char == "0": return 0
+ elif char == "1": return 1
+ elif char == "2": return 2
+ elif char == "3": return 3
+ elif char == "4": return 4
+ elif char == "5": return 5
+ elif char == "6": return 6
+ elif char == "7": return 7
+ elif char == "8": return 8
+ elif char == "9": return 9
+
#Divide()
#Histogram()
#NumberMatrix()
-#Factoriel() \ No newline at end of file
+#Factoriel()
+HappyNumber()