Variables, standard input and output, and conditional statements

From Biolecture.org
Revision as of 00:05, 4 October 2018 by imported>Yesung Lee (Created page with "<p><strong><Variables></strong></p> <p>:A name that refers to a value or an object.</p> <p>Variable names can start only with letters &underscore.</p> <p>Value assig...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

<Variables>

:A name that refers to a value or an object.

Variable names can start only with letters &underscore.

Value assignment to variable:  Use '='

e.g) greeting='Hello, World!'

n=42

<Standard input and output>

Typically, standard output is a console on the screen. Standard input is a keyboard input.

1.Print() function

print(1, 'kilobyte means', 1024, 'bytes')                                1 kilobyte means 1024 bytes

2. input() function

number=int(input('Enter a number:'))     3

print(number+1)                               4

<Control flows: conditional statements>

Ex)

number=5

if number<10:

    if number%2==0:

        print('A single digit even number')

    else:

        print('A single digit odd number')

else:

    if number%2==0:

        print('An even number with two or more digits')

    else:

        print('An odd number with two or more digits')