PYTHON

  minte9
REMEMBERS




Conditional

p85 With conditional statement we can check condtions and change the behavior.
 
# Conditional statement

n = 20

if n % 10 == 0:
    print("Number is divisible by 10")
elif n % 10 > 0:
    print("Number is not divisible by 10") 
else:
    print("Something else")

Input

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')
# John

print(name)
    # John

Fermat (A)

Check 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 fermat_was_right(a, b, c, n):
    if n <= 2:
        return True
    else:
        if (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 (fermat_was_right(a, b, c, n)):
        print('Fermat was right!')
    else:
        print('Fermat was wrong')

prompt()

Questions     github Language
Operators
        A B C D E F
🔔
1/1