Write an expression that equals 100 in python udemy

10+90 should work. Can you email udemy support? Sounds like a platform issue

On Thu, Apr 14, 2022, 1:42 AM average9871 ***@***.***> wrote: Hi - I am having an issue with the coding exercises, including coding exercise 1, not accepting my answers. For example, Coding exercise 1 would not accept answers for "write an expression that equals 100" such as 90+10 or even 100 . Can you advise what I may be doing wrong? For your reference, I am currently using Udemy for Business, which appears to have disabled both answer feedback and question replying within the Q&A sections [I also cannot see the answers to Q&A within the lectures themselves]. — Reply to this email directly, view it on GitHub , or unsubscribe . You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>

In Python most of the lines you will write will be expressions. Expressions are made of operators and operands. An expression is like 2 + 3 .

Operators¶

Operators are the symbols which tells the Python interpreter to do some mathematical or logical operation. Few basic examples of mathematical operators are given below:

>>> 2 + 3
5
>>> 23 - 3
20
>>> 22.0 / 12
1.8333333333333333

To get floating result you need to the division using any of operand as floating number. To do modulo operation use % operator

Example of integer arithmetic¶

The code

#!/usr/bin/env python3
days = int[input["Enter days: "]]
months = days / 30
days = days % 30
print["Months = %d Days = %d" % [months, days]]

The output

$ ./integer.py
Enter days: 265
Months = 8 Days = 25

In the first line I am taking the input of days, then getting the months and days and at last printing them. You can do it in a easy way

#!/usr/bin/env python3
days = int[input["Enter days: "]]
print["Months = %d Days = %d" % [divmod[days, 30]]]

The divmod[num1, num2] function returns two values , first is the division of num1 and num2 and in second the modulo of num1 and num2.

Relational Operators¶

You can use the following operators as relational operators

Relational Operators¶

Operator Meaning
< Is less than
Is greater than
>= Is greater than or equal to
== Is equal to
!= Is not equal to

Some examples

>>> 1 >> 3 > 34
False
>>> 23 == 45
False
>>> 34 != 323
True

// operator gives the floor division result

>>> 4.0 // 3
1.0
>>> 4.0 / 3
1.3333333333333333

Logical Operators¶

To do logical AND , OR we use and ,*or* keywords. x and y returns False if x is False else it returns evaluation of y. If x is True, it returns True.

>>> 1 and 4
4
>>> 1 or 4
1
>>> -1 or 4
-1
>>> 0 or 4
4

Shorthand Operator¶

x op = expression is the syntax for shorthand operators. It will be evaluated like x = x op expression , Few examples are

>>> a = 12
>>> a += 13
>>> a
25
>>> a /= 3
>>> a
8.333333333333334
>>> a += [26 * 32]
>>> a
840.3333333333334

shorthand.py example

#!/usr/bin/env python3
N = 100
a = 2
while a %2d %6.4f" % [i , sum]]

The output

$ ./evaluateequ.py
1 1.0000
2 1.5000
3 1.8333
4 2.0833
5 2.2833
6 2.4500
7 2.5929
8 2.7179
9 2.8290
10 2.9290

In the line sum += 1.0 / i what is actually happening is sum = sum + 1.0 / i.

quadraticequation.py¶

This is a program to evaluate the quadratic equation

#!/usr/bin/env python3
import math
a = int[input["Enter value of a: "]]
b = int[input["Enter value of b: "]]
c = int[input["Enter value of c: "]]
d = b * b - 4 * a * c
if d 

Chủ Đề