PW1 c2 Aykhan
PW1 c2 Aykhan
1) in line 3 it must be just one "=" not 2 and after there mustn't be "."
2)In line 6 there must be "==" because of "if" and at the end of line there must be "."
3)And in line 8 "x+=1" must be under the "if" loop not under "while"
4) And at the end of code there must be "main" not just "main"
Ex4
This is a code for all numbers from 0 to 8 to check them are they are divided by 2 and/or by 3 in 3
ways, by using constructions like if/else but all of them used di erently and of course the answers
will also be di erent. Let’s see the results
ff
ff
First function (prog 1) prints the numbers from 0 to 8 that can be divided by 2 and also numbers
from 0 to 8 that can be divided by 3
Prog 1:
0 divisible by 2
0 divisible by 3
2 divisible by 2
3 divisible by 3
4 divisible by 2
6 divisible by 2
6 divisible by 3
8 divisible by 2
Seconds function (prog 2) prints numbers from 0 to 8 that can be divided by 2 and also prints
numbers that can be divided by 3 only if they can also be divided by 2
Prog 2:
0 divisible by 2
0 divisible by 3
2 divisible by 2
4 divisible by 2
6 divisible by 2
6 divisible by 3
8 divisible by 2
Third function (prog 3) uses elif so it checks if the number from 0 to 8 can be divided by 2 if it can
the function prints the it but if the number cannot the function checks if it can be divided by 3.
Total if number cannot be divided by 2 the function will print it without checking the division by 3
Prog 3:
0 divisible by 2
2 divisible by 2
3 divisible by 3
4 divisible by 2
6 divisible by 2
8 divisible by 2
Ex5
Explanation
1) I input values: the user is prompted to enter the values for gamma and phi ( γ, φ)
2) I use the provided formula to calculate p/pt using the math module to handle the square root
3) And i: The result is printed
Ex7
Ex6
So then I used “for year in range” loop and added 1 to” years” because second part of this loop is
not included then we used math formula to calculate the balance and printed capital and years
fi
For second task :
As we can see here, i also wrote the initial capital and rate and balance that is equal to initial
capital
So in this code, I used “while” loop and until that balance is less than double capital the loop will
cycle and years will be add by 1 until the balance won’t be equal to double capital , when the
balance will equal to double capital the code will print the years that we need to make our balance
equal to double capital
Ex8
So in exercise 8
In line number four, there is the number of correct answers and the initial number of correct
answer is equals fo 0 “x”
In line number 5 it is asking for a choosing number
So in line number six, we start counting our time
And in line number 14, we stop counting our time
In line number eight, it will give us random number because of “random.randit”
So if our answer will be correct, it will add one to “x”
Say to nd the average time it will subtract the nish and current time and after it will divide the
answer by 10 because of our 10 questions
So as it was asked in the exercise for certain answers it will print certain sentences or certain
words
fi
fi
( i could not write ex1 and ex2 because I don’t have laptop)