Wednesday, 11 September 2013


If you want to know how to solve the problem "Dog years" then have a look at how to do it. 

a) Write the question:

It is an  often quoted (although not entirely accurate) 'fact' that 1 dog year is equivalent to 7 human years. Write a program that converts an age in dog years to human age.
Your program should work like this:

Dog Years: 3
Human age = 21

and like this:

 
Dog Years: 7

Human age = 49

The first time i tryed this question i wrote:
year = input("Dog years: ")

Then i didn't know what to do next. Then i taught to do it step by step. So i started with:


b) Describe the problem: 
This problem is designed to help create the code that helps figure out humans age if we write dogs age.This is a problem that can be used in real world. This is a easy way of figuring out humans age is we write the dogs age, and it always works for this question.

They may not give you formulas, but you can strait away see the pattern in the question.
The pattern is multiply 7 to the dogs age.

c) Solve the problem:

It lookes hard but lets have a go it.

start of with telling the program:

years =input('Dog years: ')Use "input" so that your program knows that if we type in any age for the dog the, humans age shoud be times the dogs age.

Since there are all numbe answers tell the program to add "int" to its starting sentence (years):

dog int(input('Dog years: "))
So far we asked the program to multiply the dogs age (any number) to the humans age (times 7)
Nect we have to ask it to print the Humans age. To start type in:
print('Human age: ' (dog*7))

Now we have to tell the program that there is going to be words in the solution so we need to add "str":
print('Human age: ' +""+ str(dog*7))

This is the solution:

dog int(input('Dog years: "))
print('Human age: ' +""+ str(dog*7))
To solve this problem we used 3 steps:
1. Look at the question
2.Describe the question
3.Solve the problem



Test before submitting!!






If you want to know how to solve another problem look below.

a) Write the question:
Write a program to work out whether a line of input text contains a bear or not. Your program needs to find cases where the word appears in full, with no breaks. For example:

Enter line: Please don't feed the bear.
There's a bear in there.
 

However, if the user enters a line which does not contain bear:

Enter line: The room had a chair and a table.
No bears here.

I started with:
input("Enter line: ")
print("There's a bear in there.")


print("No bears here.")


I tried runing it but it didn't work. So i started again like :

 

b) Describe the question:
This problem is designed to help create the code that helps figure out If there is a bear. This is a problem that can be used in games if you have to find a bear. This is a easy way to figure out if there is a bear or not. To solve this problem think we are in a game and in the game we have to write a sentence and if there is "bear" in the sentence then the game should say "There's a bare in there." or it should just say "No bears here.".



c) Solve the problem:
So first you want to be able to write a sentence in the game.
start with:
line = input('Enter line: ')
Next we want to the game to say "There's a bare in there" if the sentence has "bear in it:
if "Bear" in line:
print("There's a bear in there.")
Now we want the game to say "No bears here." if the sentence doesn't have "bear" in it.
else:
print("No bears here." )

So the answer is:
line = input('Enter line: ')

if "Bear" in line:
print("There's a bear in there.")

else:
print("No bears here." )

1. Look at the question
2.Describe the question
3.Solve the problem

Test before submitting!!

No comments:

Post a Comment