Learning Python from the Codeschool

There is a funny women on the Web that give lessons of Python and I really enjoy to see her videos and challenges. It is not the traditional professor with a blackboard in behind. Here are some challenges that I resolved as a Python beginner:

1.1. MATH

1.2 Happy Birthday

>>>2016 - 1732
284

1.3 Your Age in Dog Years

284/7
40.5714

1.4 Calculating British Money Spent

>>> 200*0.65
130.0
>>> (200-2)*0.65
128.70000000000002
>>> ((200-2)*0.65)-100
28.700000000000017

1.6 Naming Variables

us_currency

1.7 Variable Calculations

70

1.8 Exchange Rate Calculations

x_rate = 0.65
total_usd = 200
fee_usd = 2
total_gbp = (total_usd - fee_usd)*x_rate

1.9 Exchange Rate Calculations 2

>>> total_usd
42.15384615384618
>>> import math
>>> math.ceil(total_usd)
43

2.1. STRINGS

2.2 Print Output

G'day

2.3 String Concatenation

greeting = "G'day"
new_string = 'mate'
print (greeting+' '+new_string)

2.4 Cast Number to String

str(number)

2.5 Getting Started With Python Strings

name = "Friends"
description = "a group of friends, lives in NY"
year = 2000
sentence = "My favorite sketch is "+name+" where "+description+"in "+str(year)+"."
print(sentence)

2.6 String Formatting

movie1 = "The planet of apes"
movie2 = "La vita e bela"
print ("My Favorite Movies:\n\t",movie1,"\n\t",movie2)

2.8 Slicing to Create a Substring

sub_word = word[2:6]

2.9 Pythonese

word = 'Python'
first = word[0]
rest = word[1:]
result = rest+"-"+first+"y"
print(result)

3.1. Introduction to Conditionals

3.2 Choosing the Right Conditional Operator

answer = 5 < 10
answer = 5<=10

3.3 Comparison Operators

answer = 5 == 5
print(answer)

3.4 If Else

rain_speed = 7
if rain_speed < 5:
   print ("Just a Scotch mist")
else:
   print ("It's a real Cow-quaker out there")

3.6 If Elif Else

Hola

3.7 Input

name = input('Enter your name')

3.8 Rock-Paper-Python

computer_choice = 'rock'
user_choice = input("Enter rock, paper, or python:\n")
if computer_choice == user_choice:
    print('TIE')
else:
    print("You lose :( Computer wins :D")

3.9 Improving Rock-Paper-Python

computer_choice = 'rock'
user_choice = input("Enter rock, paper, or python:\n")
if computer_choice == user_choice:
  print('TIE')
elif user_choice == 'rock' and computer_choice == 'python':
  print('WIN')
elif user_choice == 'paper' and computer_choice == 'rock':
  print('WIN')
elif user_choice == 'python' and computer_choice == 'paper':
  print('WIN')
else:
  print('You lose :( Computer wins :D')

About Julita Inca

Ingeniero de Sistemas UNAC, Magíster en Ciencias de la Computación PUCP, OPW GNOME 2011, Miembro de la GNOME Foundation desde el 2012, Embajadora Fedora Perú desde el 2012, ganadora del scholarship of the Linux Foundation 2012, experiencia como Admin Linux en GMD y Especialista IT en IBM, con certificaciones RHCE, RHCSA, AIX 6.1, AIX 7 Administrator e ITILv3. Experiencia académica en universidades como PUCP, USIL y UNI. HPC researcher, a simple mortal, like you!
This entry was posted in τεχνολογια :: Technology. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s