minte9
LearnRemember



Conditional

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

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)

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()



  Last update: 303 days ago