示例#1
0
文件: answer.py 项目: neskoc/oopython
#
# In the code below create a new variable called **per** and set it to a new
# instance of Person. Give it the name `Farseer` and ssn `578118-6946`.
#
#
# Answer with per\'s getter for ssn.
#
# Write your code below and put the answer into the variable ANSWER.
#

per = Person("Farseer", "578118-6946")

ANSWER = per.get_ssn()

# I will now test your answer - change false to true to get a hint.
dbwebb.assert_equal("1.1", ANSWER, False)

# """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
# Exercise 1.2 (2 points)
#
# Create a new class named **Address**.  Give the class the instance
# attributes "city", "state" and "country". The values for the attributes
# should be sent to the constructor as arguments.
# Create the magic method **_\_str_\_**, in Address, it should return
# `"Address: <city> <state> <country>"` (replace the \<city\> with the value
# of the attribute city...).
#
# Create a new instance of the class Address. Initiate it with the city
# `Katar`, the state `Blekinge` and the country `Shienar` and store it in a
# variable called **per_address**.
#
示例#2
0
# Write a pattern that matches the word `can` in the sentence
# 'how can a clam cram in a clean cream can?'.
#
# Use the re modules findall function.
#
# Write your code below and put the answer into the variable ANSWER.
#

line = "how can a clam cram in a clean cream can?"

can = re.findall("can", line)

ANSWER = can

# I will now test your answer - change false to true to get a hint.
dbwebb.assert_equal("1.1", ANSWER, False)

# """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
# Exercise 1.2 (1 points)
#
# Write a pattern that only matches the words that start with a *big letter*
# in the sentence
# 'Droskkusken Max kuskar med Fuxar och fuskar med droskkusktaxan.'.
#
# Use the re modules findall function.
#
# Write your code below and put the answer into the variable ANSWER.
#

line = "Droskkusken Max kuskar med Fuxar och fuskar med droskkusktaxan."
示例#3
0
#
#
# Initialize a new variable called `date1` which contains a *Date object*,
# give it year `2005`, month `1` and day `4`.
#
# Answer with the result from the info method.
#
# Write your code below and put the answer into the variable ANSWER.
#

date1 = myDate.Date(2005, 1, 4)

ANSWER = date1.info()

# I will now test your answer - change false to true to get a hint.
dbwebb.assert_equal("1.1", ANSWER, False)

# """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
# Exercise 1.2
#
# Overload the `smaller than method(<)` in the Date class.
# It should return True if date comes before the other.
#
# Initialize a new Date variable called `date2` , give it year `2000`, month
# `11` and day `26`.
#
# Answer with `date1<date2`.
#
# Write your code below and put the answer into the variable ANSWER.
#
示例#4
0
#
# Answer with the boolean value of the expression '`dice1` is greater than
# `dice2`'.
#
# Write your code below and put the answer into the variable ANSWER.
#

dice1 = 5
dice2 = 5
dice3 = 2
booleanValue = dice1 > dice2

ANSWER = booleanValue

# I will now test your answer - change false to true to get a hint.
dbwebb.assert_equal("1.1", ANSWER, False)

# """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
# Exercise 1.2 (1 points)
#
# Sum the three variables `dice1`, `dice2` and `dice3`.
#
# Use an if-statement to decide if the sum of the three variables i greater
# than 11. If the sum is greater than 11 answer with 'big' otherwise answer
# with 'small'.
#
# Write your code below and put the answer into the variable ANSWER.
#

sum_of_all = dice1 + dice2 + dice3
result = ""