yasar84 / week2

Loops, Git and GitHub exercises

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Week 2

Loops, Lists, If Conditions

Chapter 5. IF Statements

Programming often involves examining a set of conditions and deciding which action to take based on those conditions. Python’s if statement allows you to examine the current state of a program and respond appropriately to that state.

In this chapter you’ll learn to write conditional tests, which allow you to check any condition of interest. You’ll learn to write simple if statements, and you’ll learn how to create a more complex series of if statements to identify when the exact conditions you want are present. You’ll then apply this concept to lists, so you’ll be able to write a for loop that handles most items in a list one way but handles certain items with specific values in a different way.

Simple Example

The following short example shows how if tests let you respond to special situations correctly. Imagine you have a list of cars and you want to print out the name of each car. Car names are proper names, so the names of most cars should be printed in title case. However, the value 'bmw' should be printed in all uppercase. The following code loops through a list of car names and looks for the value 'bmw'. Whenever the value is 'bmw', it’s printed in uppercase instead of title case:

cars = ['audi', 'bmw', 'subaru', 'toyota']
for car in cars:
   if car == 'bmw':
       print(car.upper())
   else:
       print(car.title())

Afterword D

Version control software allows you to take snapshots of a project whenever it’s in a working state. When you make changes to a project—for example, when you implement a new feature—you have the option of reverting back to a previous working state if the project’s current state isn’t functioning well. Using version control software gives you the freedom to work on improvements and make mistakes without worrying about ruining your project. This is especially critical in large projects, but can also be helpful in smaller projects, even when you’re working on programs contained in a single file.

CREATE REPOSITORIES

Start a new repository or obtain one from an existing URL.

Creates a new local repository with the specified name

$ git init [project-name]

Downloads a project and its entire version history

$ git clone [url]

For more download the git cheatsheet.

Find GitHub Desktop guide here.

Steps to clone the project

  1. Copy the url of the repository ending with .git (https://github.com/2019-spring/week2.git)

  2. GitHub Desktop:

    • Go to Current Repository
    • click on Add drop down
    • Clone Repository
    • click on URL tab
    • paste the copied URL (https://github.com/2019-spring/week2.git)
    • choose the location from your local machine C:\dev\ then click on Clone.

    Git Bash: navigate to the right directory C:\dev\ and enter following:

git clone https://github.com/2019-spring/week2.git
  1. [optional] Create your feature branch:
git checkout -b week2_john
  1. Open the C:\dev\week2 folder from your VS Code and start modifying the code.

References

About

Loops, Git and GitHub exercises


Languages

Language:Python 100.0%