Hacks Pt. 1

  • Evaluate the result

My Predictions:

  1. Result = 20.4, but prints nothing in the output
  2. Result = 0, but prints nothing in the output
  3. Value C gets printed which is 17
  4. hair = "straightbrownshort" and that gets printed
Num1 = 50
Num2 = Num1 % 9 + 15
Num3 = Num2 / Num1 + ( Num2 * 2 )
Num4 = Num3 + Num1 / 5 - 10
Result = Num4 - Num2
print(Result)
20.4
Num1 = 10
Num2 = Num1 % 3 * 4
Num1 = Num2
Num3 = Num1 * 3
Result = Num3 % 2  
print(Result) 
0
valueA = 4
valueB = 90
valueC = 17
valueB = valueC - valueA
valueA = valueA * 10
if valueB > 10:
    print(valueC)   
17
type = "curly"
color = "brown"
length = "short"
type = "straight"
hair = type + color + length
print(hair)
straightbrownshort

Hacks Pt. 2

  • Collection of character (#s, letters, spaces, special characters)
  • procedures can be used with strings
    • len() finds length of strings
  • concatenation combines strings
    • concat("cookie", "monster") outputs "cookiemonster"

Problem #1 Code then Answer:

Noun = "Mr.Mortenson" 
Adjective = "handsome" 
Adjective2 = "Very" 
Verb = "is" 
abrev = subtring(Noun, 1, 7) # Abbreviate "Mr.Mortensen" to "Mr.Mort"
yoda = concat(Adjective2, " ", Adjective, " ", abrev, " ",Verb, ".") # yoda = VeryhandsomeMr.Mortis
display[yoda]
Noun = "Mr.Mortenson" 
Adjective = "handsome" 
Adjective2 = "Very" 
Verb = "is" 
abrev = Noun[:7]
yoda = abrev + " " + Verb + " " + Adjective2 + " " + Adjective + "."
print(yoda)
Mr.Mort is Very handsome.

Problem #2 Code then Answer:

cookie = "choclate" 
cookie2 = "rasin" 
len1 = len(cookie) / 2 # len1 = 4
len2 = len(cookie2) * 45 # len2 = 225
vote1 = (cookie, "vote", len2) # vote1 = choclate vote 225
vote2 = (cookie2, "vote", len1) # vote2 = rasinvote4
votes = concat(vote1, " ", vote2) # votes = choclate vote 225 rasin vote4
display[votes]
cookie = "choclate" 
cookie2 = "rasin" 
len1 = len(cookie) / 2 
len2 = len(cookie2) * 45 
vote1 = (str(cookie) + " vote " + str(len2))
vote2 = (str(cookie2) + " vote " + str(len1))
votes = (str(vote1) + " " + str(vote2))
print(votes)
choclate vote 225 rasin vote 4.0