You are on page 1of 4

1/28/2021 Python for O&G lecture 7 - Input Function - Part 1 - Colaboratory

Python for Oil and Gas

Website - https://petroleumfromscratchin.wordpress.com/

LinkedIn - https://www.linkedin.com/company/petroleum-from-scratch

YouTube - https://www.youtube.com/channel/UC_lT10npISN5V32HDLAklsw

input('What do you do?')

What do you do?Student


'Student'

# input function in a variable

/
1/28/2021 Python for O&G lecture 7 - Input Function - Part 1 - Colaboratory

name = input('What is your name?')

What is your name?Divyansh Sethi

print(name)

Divyansh Sethi

# Hi, Divyansh Sethi. Welcome back!

print(f'Hi {name}. Welcome back!')

Hi Divyansh Sethi. Welcome back!

siblings = input('How many siblings do you have?')

How many siblings do you have?3

print(siblings)

print('I have' + ' ' + siblings+ ' ' + 'siblings')

I have 3 siblings

# input function always takes your answers in string

type(siblings)

str /
1/28/2021 Python for O&G lecture 7 - Input Function - Part 1 - Colaboratory

age = input('What is my age? ')


dad_age = input('What is your dad age? ')

What is my age? 24
What is your dad age? 49

print(age)

24

print(dad_age)

49

age_sum = age + dad_age

print(age_sum)

2449

print('a' + 'b')

ab

Use of int()

age_sum_2 = int(age) + int(dad_age)


print(age_sum_2)

73 /
1/28/2021 Python for O&G lecture 7 - Input Function - Part 1 - Colaboratory

age_2 = int(input('What is my age? '))


dad_age_2 = int(input('What is your dad age? '))

What is my age? 25
What is your dad age? 47

print(age_2 + dad_age_2)

72

You might also like