0% found this document useful (0 votes)
44 views

Automate Boring Stuff With Python - Colaboratory

The document contains examples of Python code demonstrating basic programming concepts like variables, input/output, conditional statements, loops, and boolean logic. It shows how to get user input, perform string operations and comparisons, use if/else statements to check conditions, iterate with while loops, and break out of loops. The code snippets are accompanied by explanations and output to illustrate each concept.

Uploaded by

gomerdavid13
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views

Automate Boring Stuff With Python - Colaboratory

The document contains examples of Python code demonstrating basic programming concepts like variables, input/output, conditional statements, loops, and boolean logic. It shows how to get user input, perform string operations and comparisons, use if/else statements to check conditions, iterate with while loops, and break out of loops. The code snippets are accompanied by explanations and output to illustrate each concept.

Uploaded by

gomerdavid13
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

1/2/24, 13:36 automate boring stuff with python - Colaboratory

# This program says hello and asks for my name.


print('Hello!')
print('What is your name?') # ask for their name
myName = input()
print('It is good to meet you, ' + myName)
print('The length of your name is:')
print(len(myName))
print('What is your age?') # ask for their age
myAge = input()
print('You will be ' + str(int(myAge) + 1) + ' in a year.')

Hello!
What is your name?
eme
It is good to meet you, eme
The length of your name is:
3
What is your age?
22
You will be 23 in a year.

len("42")

print("I am " + str( 41 )+ " years old") # example that concatenate string expressions

I am 41 years old

42==13 # boolen operators examples

False

44==99

False

2!=2

False

33<=55

True

True!= False

True

"dog"=="cat"

False

False and True

False

False or False

False

not True

False

not not not not True

True

https://colab.research.google.com/drive/1EHGqpKMhNFbeJa6N7GQduadc0XtZiIpl#scrollTo=Qi70xV0SJxxn&printMode=true 1/3
1/2/24, 13:36 automate boring stuff with python - Colaboratory
(4<5)and(5<6)

True

(4<5)and(9<6)

False

(1==2) or (2==2)

True

2+2==4 and not 2+2==5 and 2*2==2+2

True

name = input("what´s your name ") # example of an indentation code


if name == 'Mary':
print('Hello Mary')
password = input("please type your password ")
if password =='swordfish':
print('Access granted.')
else:
print('Access denied.')
print('Wrong password.')

what´s your name Mary


Hello Mary
please type your password sowrfish
Access denied.
Wrong password.

name = input("What is your name beautiful lady? ")


if name in ["eme", "maría", "eme maría", "eme maría garcía", "eme maría garcía henao"]:
print('Hi, eme.')

What is your name beautiful lady? eme maría garcía


Hi, eme.

name = input("What is your name beautiful lady? ")


age = input("what´s your age maría? ")
if (name == "eme" or name == "maría" or name == "eme maría" or name == "eme maría garcía" or name == "eme maría
print('Hi, eme maría.')
elif int(age) <= 12:
print('You are not eme maría, kiddo.')
elif 12 < int(age) < 33:
print('You seem to be too young to be eme maría.')
elif int(age) >= 40:
print('You are not eme maría, grannie.')

What is your name beautiful lady? eme maría


what´s your age maría? 44
You are not eme maría, grannie.

spam = 0
while spam < 5:
print('Hello, world.')
spam = spam + 1

Hello, world.
Hello, world.
Hello, world.
Hello, world.
Hello, world.

name = '' # an infinite loop


while name != 'your name':
print('Please type your name.')
name = input()
print('Thank you!')

name = input("Please type your name: ")


while name != "your name":
https://colab.research.google.com/drive/1EHGqpKMhNFbeJa6N7GQduadc0XtZiIpl#scrollTo=Qi70xV0SJxxn&printMode=true 2/3
1/2/24, 13:36 automate boring stuff with python - Colaboratory
while name ! your name :
name = input("Please type your name: ")
else:
print("Thank you")

output Please type your name: david


Please type your name: eme maría
Please type your name: your name
Thank you

while True: # break example


print('Please type your name.')
name = input()
if name == 'eme':
break
print('Hi! ' + name)

Please type your name.


david
Please type your name.
camila
Please type your name.
eme
Hi! eme

https://colab.research.google.com/drive/1EHGqpKMhNFbeJa6N7GQduadc0XtZiIpl#scrollTo=Qi70xV0SJxxn&printMode=true 3/3

You might also like