aboutsummaryrefslogtreecommitdiff
path: root/Python/Beginner training
diff options
context:
space:
mode:
Diffstat (limited to 'Python/Beginner training')
-rw-r--r--Python/Beginner training/.idea/Beginner training.iml2
-rw-r--r--Python/Beginner training/.idea/misc.xml4
-rw-r--r--Python/Beginner training/Tasks.py41
3 files changed, 45 insertions, 2 deletions
diff --git a/Python/Beginner training/.idea/Beginner training.iml b/Python/Beginner training/.idea/Beginner training.iml
index 85c7612..fa80a76 100644
--- a/Python/Beginner training/.idea/Beginner training.iml
+++ b/Python/Beginner training/.idea/Beginner training.iml
@@ -4,7 +4,7 @@
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/venv" />
</content>
- <orderEntry type="inheritedJdk" />
+ <orderEntry type="jdk" jdkName="Python 3.7" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="TestRunnerService">
diff --git a/Python/Beginner training/.idea/misc.xml b/Python/Beginner training/.idea/misc.xml
new file mode 100644
index 0000000..a2e120d
--- /dev/null
+++ b/Python/Beginner training/.idea/misc.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+ <component name="ProjectRootManager" version="2" project-jdk-name="Python 3.7" project-jdk-type="Python SDK" />
+</project> \ No newline at end of file
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()