 # Integers s150042028

Where is the exercise like the previous chapter? Just watching the video is not a useful way to practice. Very bad! Bartosz Zaczyński RP Team

@s150042028 The video courses belonging to the Python Basics learning path didn’t originally come with exercise solutions. It’s only recently that we’ve started recording them. The one for this course is currently on its way and will be published soon. Until then, you can refer to the course materials or check the solutions on our GitHub repository.

If you have specific questions, then you’re more than welcome to ask them on Real Python’s Slack community or during Office Hours, which is a live Q&A session hosted weekly. s150042028

I don’t need exercise solutions. I will answer the exercises myself, such as the ones in the String module. Please refer to the String module by the end of the lesson. There are a lot of exercises set there. Martin Breuss RP Team

@s150042028 here you go, some exercises for you to preview and work through. You’ll see them introduced and solved in the upcoming exercises course as well:

Creating Integers and Floating-Point Numbers

• Write a program that creates two variables, `num1` and `num2`. Both `num1` and `num2` should be assigned the integer literal `25000000`, one written with underscores and one without. Print `num1` and `num2` on two separate lines.

• Write a program that assigns the floating-point literal `175000.0` to the variable `num` using E notation and then prints `num` in the interactive window.

• In IDLE’s interactive window, try to find the smallest exponent `N` for which `2e<N>`, where `<N>` is replaced with your number, returns `inf`.

Formatting Numbers as Strings

• Print the result of the calculation `3 ** .125` as a fixed-point number with three decimal places.

• Print the number `150000` as currency with the thousands grouped with commas. Currency should be displayed with two decimal places.

• Print the result of `2 / 10` as a percentage with no decimal places. The output should look like `20%`.

Getting Numbers From the User

Write a program called `exponent.py` that receives two numbers from the user and displays the first number raised to the power of the second number.

Here’s sample run of what the program should look like, including example input from the user:

``````Enter a base: 1.2
Enter an exponent: 3
1.2 to the power of 3 = 1.7279999999999998
``````

Keep the following in mind:

1. Before you can do anything with the user’s input, you’ll have to assign both calls to `input()` to new variables.
2. `input()` returns a string, so you’ll need to convert the user’s input into numbers to do arithmetic.
3. You can use an f-string to print the result.
4. You can assume that the user will enter actual numbers as input.

Using Math Functions and Number Methods

• Write a program that asks the user to input a number and then displays that number rounded to two decimal places. When run, your program should look like this:
``````Enter a number: 5.432
5.432 rounded to 2 decimal places is 5.43
``````
• Write a program that asks the user to input a number and then displays the absolute value of that number. When run, your program should look like this:
``````Enter a number: -10
The absolute value of -10 is 10.0
``````
• Write a program that asks the user to input two numbers by using `input()` twice, then displays whether the diﬀerence between those two numbers is an integer.

When run, your program should look like this:

``````Enter a number: 1.5
Enter another number: .5
The difference between 1.5 and .5 is an integer? True!
``````

If the user inputs two numbers whose diﬀerence is not integral, then the output should look like this:

``````Enter a number: 1.5
Enter another number: 1.0
The difference between 1.5 and 1.0 is an integer? False!
`````` Bartosz Zaczyński RP Team

@s150042028 Here’s the promised video course with the exercises: realpython.com/courses/numbers-and-math-exercises/

to join the conversation.

Lesson Completed!
Lesson Bookmarked
Request Failed :(