Starting from:

$29.99

CSE101 Lab 1 - Arithmetic in python Preliminaries Solution

GitHub Classroom

Lab 1 - Arithmetic in python
Preliminaries
Write your first executable program !

1. Create a python file
Use your favorite editor
(VSCodeQuizzes, Notepad++, etc.) and create a
python file “Hello.py”. And save it at the location you like.
2. Write your code
In the first line, type Quizzes the following: print(“Hello world.”)
Save and exit
3. Run your code
Execute by typing this Quizzes command in the terminal: python hello.py

Preliminaries
You can also replace this line with a more complex code!
num = 10 # You can change this later other_num = num * 4 print(other_num) print(num) print(str(num))
# Not a very useful code, though
What are the ‘#’ symbols?
• Comments! • Use as often as you can: in-code documentation is a very good habit
What does the ‘str(…)’ code do?
• That’s a conversion-to-string code
• It’s used to convert the given data into a string
• What happens if we don’t use str(…) ?
Quadratic equation
Task 1
– Complete the first part of quad.py
– Need to fill in the ellipsis (…) to implement the quadratic formula Remember there are two roots!
– Conditions
– You must only use arithmetic operators
– Do not use anything we haven’t learned in class yet. That qualifies as a 0.
– Do not change anything besides the two lines you’re supposed to add
Task 2
– Let’s do division (for kids)
– When you divide two numbers, you get a quotient and a remainder
– 3 / 2 is 1 with remainder 1
– 10 / 3 is 3 with remainder 1 1 / 4 is …?
– In this task, you are to declare two variables x and y
– Initialize them to whatever positive values you like You should compute a quotient and a remainder
3
1
– E.g., for x = 10 and y = 3, the output should look like this:
– Same conditions as task 1
– Fill in quad.py’s second part


GitHub Classroom

Lab 1 - Arithmetic in python
1. Accept the GitHub invitation

If you click on the link we can see the content of the repository


Copy this link
1. Create a folder called “CSE101” somewhere in your computer
2. Run VSCode
3. Press Ctrl + ` Or press View/Terminal to open a terminal in VSCode
4. Go to the folder you created by typing
cd path_to_folder
5. Now clone the git repository
git clone repository_link
(let’s say the folder is located in C:UsersDELLDocumentsCodeCSE101)
I will type: cd C:UsersDELLDocumentsCodeCSE101
Note that you do not need to recreate a new folder for each new assignments/lab since the clone function directly create sub directories
Here is what you should get

Now go to the folder you have cloned in VSCode  File/Open Folder and Select the folder lab1---arithmetic-in-python-yourgitaccount

2. Time to code
Code whatever you want
We modified this line

a = 1 b = -3 c = 1
x1 = ... x2 = ... print("First root:" + str(x1)) print("Second root:" + str(x2))

a = 1 b = -3 c = 1
x1 = a - b x2 = ...
print("First root:" + str(x1)) print("Second root:" + str(x2))

You can test your code by writing in the terminal
python my_code.py
3. Commit and push
2. Write the message corresponding to your new commit

Press the button “Commit & Push”
Verify

Now you can go back to the repository to see if your changes have been uploaded

More products