Python
/
Language
- 1 Language 9
-
Hello World S
-
Variables S
-
Functions S
-
Conditional A S
-
Operators S
-
While S
-
Turtle S
-
Script Mode S
-
Debugging S
- 2 Strings 7
-
Slice S
-
Raw Strings S
-
Regex A S
-
Validation S
-
Config S
-
Security S
-
Encrypt A S
- 3 Collections 6
-
Lists S
-
Dictionaries S
-
Efficiency S
-
Tree S
-
Tuples S
-
References S
- 4 Functions 5
-
Recursion S
-
Factorial S
-
Modulus S
-
Reassignment S
-
Approximate S
- 5 Storage 8
-
Files S
-
Databases S
-
Pipes S
-
With open S
-
Shelve A S
-
Zip S
-
Csv S
-
Json S
- 6 Class 4
-
Definition S
-
Attributes S
-
Functional S
-
Methods S
- 7 Goodies 5
-
Conditional Expression S
-
List Comprehension A S
-
Generator S
-
Named Tuple S
-
Modules S
- 8 Applications 5
-
Pythagora A S
-
Palindrome A S
-
Binary Search A S
-
Conway Game A S
-
Coin Flip A S
- 9 Scheduler 4
-
Time S
-
Multithreading A S
-
Subprocess S
-
Logging S
- 10 Packages 6
-
Clipboard A S
-
Ocr A S
-
Socket S
-
Image S
-
Virtualenv S
-
Jupyter S
S
R
Q
Python Language Conditional
Check condtions and change the behavior Fermat's last theorem def check(a, b, c, n): if n <= 2: return True elif (a**n + b**n == c**n): return False return True
Conditional
1 p85 With conditional statement we can check condtions and change the behavior.
""" Conditional statement
"""
n = 20
if n % 10 == 0:
print("divisible by 10") # divisible by 10
elif n % 10 > 0:
print("not divisible by 10")
else:
print("else")
Input
1 p93 Python provides a function that stops the program and waits for the user input.
""" Input function waits for user input
"""
name = input('What is your name?\n')
# type: John
print(name)
# output: John
➥ Fermat (A)
Fermat (A)
Check Fermat's last theorem.
""" Fermat's last theorem
For any number > 2, there are no positive integers
a, b, c, so that a**n + b**n = c**n
"""
def check(a, b, c, n):
if n <= 2:
return True
elif (a**n + b**n == c**n):
return False
return True
def prompt():
a = int(input('Input a? '))
b = int(input('Input b? '))
c = int(input('Input c? '))
n = int(input('Input n? '))
if (check(a, b, c, n)):
print('Fermat was right!')
else:
print('Fermat was wrong')
prompt()
➥ Questions