Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Created and completed the all homework project #23

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,17 @@
//: Next, learn how programmers can leave notes in code.
//:
//:[Previous](@previous) | page 3 of 7 | [Next: Comments](@next)
23 + 45 + 33

67 - 44

7 * 88

69 / 69

(67 + 77 + 55 + 44 ) / 8





Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,9 @@
//:
//: A comment starts with two slashes `//` :
// This is a comment; it does not affect the code
34 + 56 + 230
34 + 56 + 230 //don't forget to add 230
//: Because comments are ignored, no result is displayed in the results bar for that line of code.
// 200 + 34 + 45
//: - experiment:\
//: Try _commenting out_ the calculation `34 + 56 + 230` by adding two slashes to the beginning of the calculation.\
//:Try _uncommenting_ the calculation `200 + 34 + 45` by deleting the two slashes.\
//:Edit some of the existing expressions and add a few of your own.\
//:Notice that every time you make a change the results are updated in the sidebar.
//:
//: Take a deep breath and move on to the next page.
//:
//:[Previous](@previous) | page 4 of 7 | [Next: When Things Go Wrong 😰](@next)
200 + 34 + 45


//this is a addtion operation
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//: This playground page, for example, has an error in it.
//:
//: 👈 Notice the red error symbol to the left of the line below. This is how a playground tells you where a problem is.
1000 / 0
1000 / 2000
//: Since there is an error, the playground stops running your code.\
//: Notice that there are no results displayed in the sidebar. 👉
2 + 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,8 @@ Next, find out how to put the results sidebar to better use.
[Previous](@previous) | page 2 of 7 | [Next: Calculations](@next)
*/

23

54


Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,32 @@
(150 * 10) - (1000 + 40)
//: - callout(Exercise): Using the code above as a reference, use let statements to define constants to better solve your friend’s problem.\
//:Add your code below. To help you get started, the constant `numberOfTickets` is already defined.

let numberOfTickets = 150

let ticketPrice = 10

let roomRentalFee = 1000

let posterCost = 40

let totalTicketValue = 150 * 10

let totalExpenses = 1000 + 40

let totalIncomeOfShow = (150 * 10) - (1000 + 40)
//:
//:[Previous](@previous) | page 10 of 14 | [Next: Exercise: Lottery Tickets](@next)
let numberOfTickets2 = 150

let ticketPrice2 = 10

let roomRentalFee2 = 1000

let posterCost2 = 40

let totalTicketValue2 = 150 * 10

let totalExpenses2 = 1000 + 40

let totalIncomeOfShow2 = (150 * 10) - (1000 + 40)
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,27 @@
Another reason that naming things and only setting a value once is useful is that it lets you decide on the correct way of calculating something, then change the values and check the answers.
*/
// Values you should edit
// Incoms
let ticketsSold = 1000
let ticketPrice = 1
let ticketPrice = 2

// Expenses
let printingCosts = 20
let advertising = 50
/*:
- callout(Exercise): You’ve done enough work for free for your friend. For this venture, your friend will give you a cut of the profits in return for your help. Your friend will give you a tenth of the profits. The jackpot is half of the total ticket sales money. Try changing the numbers above - tickets sold, ticket price, printing or advertising costs and see if you can get your cut up to 100 or more.

The calculations below are fixed, but you can change the results by changing the numbers above:
*/
//:[Previous](@previous) | page 11 of 14 | [Next: Exercise: What Fits on Your iPhone?](@next)
// Total takings
let totalTakings = ticketPrice * ticketsSold
let totalTicketsIncome = ticketsSold * ticketPrice

// Jackpot
let jackpot = totalTakings / 2
let jackpot = totalTicketsIncome / 2

// Expenses
let totalExpenses = printingCosts + advertising

// Profit
let profit = totalTakings - jackpot - totalExpenses
let profit = totalTicketsIncome / totalExpenses

// Distribution
let programmersCut = profit / 10 // This is the answer you want to get over 100! 👉
let programmersCut = profit / 10 // This is the answer you want to get over 100! 👉
let friendsCut = profit - programmersCut

//:[Previous](@previous) | page 11 of 14 | [Next: Exercise: What Fits on Your iPhone?](@next)
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
_Hint_: Do all of your calculations in megabytes (MB).
*/

let iPhoneStorageInMegaBites = 8 * 1000
let iPhoneStorageUsedInMegaBites = 3 * 1000
let OneMinuteOfVideoUsedInMegaBites = 150

let minutesToFillThePhone = (iPhoneStorageInMegaBites - iPhoneStorageUsedInMegaBites) / OneMinuteOfVideoUsedInMegaBites



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,46 @@
- callout(Exercise): Create a constant for each activity you do in the morning before leaving home: things like `brushTeeth`, `uploadPhotos`, `chooseClothes`, `shower`, `goJogging`, `finishHomework`, `fixLunch`, and so on. Think about how many minutes each activity usually takes, and assign that value to each constant.
*/
let brushTeeth = 3
// Add more here...
let upLoadPhotos = 5
let chooseClothes = 4
let shower = 10
let goJogging = 50
let finishHomeWork = 30
let fixlunch = 10

//: - callout(Exercise): Find the total time of all the activities by adding up the constants. Try to adjust the values or add more activities until the total time looks reasonably close to the actual amount of time you spend getting ready on an average day.

//: - callout(Exercise): Find the total time of all the activities by adding up the constants. Try to adjust the values or add more activities until the total time looks reasonably close to the actual amount of time you spend getting ready on an average day.
let totalTime = brushTeeth + upLoadPhotos + chooseClothes + shower + goJogging + finishHomeWork + fixlunch


//: - callout(Exercise): Add up the constants again, but this time in separate groups: one group for things you have to do and another group for things you like to do.\
//:\
//:If there are things you don’t have to do and don't like to do, make a third group and go ahead and sum that one, too. \
//:\
//:Make a new constant for each group.
let thingsIHaveToDo = brushTeeth + upLoadPhotos + shower + finishHomeWork
let thingsILikeToDo = chooseClothes + goJogging + fixlunch

let totalTime2 = thingsIHaveToDo + thingsILikeToDo


/*:
See what happens to your total time spent getting ready if you tweak the durations of the different activities. How short of a shower would you have to take in order to have more time to message your friends? Or go for a longer run? How much more time would you need if you decided to spend as long as you wanted doing all the activities you like best?

Change the numbers until you’ve got a design for your ideal morning. What would have to change in order for you to be able to actually spend your morning time this way?
*/

let brushTeeth2 = 4
let upLoadPhotos2 = 5
let chooseClothes2 = 4
let shower2 = 9
let goJogging2 = 40
let finishHomeWork2 = 35
let fixlunch2 = 5

let thingsIHaveToDo2 = brushTeeth2 + upLoadPhotos2 + shower2 + finishHomeWork2
let thingsILikeToDo2 = chooseClothes2 + goJogging2 + fixlunch2

let totalTime3 = thingsIHaveToDo2 + thingsILikeToDo2



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,16 @@ let rhso = co - lhso


//: - experiment: Rewrite the code so that it makes sense without needing a note. Use meaningful names and comments.

let countOrange = 14
let countWatermelons = 3
let orangeWeigh = 100
let watermelonsWeigh = 200
let truckOrange = countOrange * orangeWeigh
let truckWatermelons = countWatermelons * watermelonsWeigh
let trucktotal = truckOrange + truckWatermelons
let eachSide = trucktotal / 2
let leftHandSide = eachSide / orangeWeigh
let rightHandSide = countOrange - leftHandSide



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,15 @@ let numberOfTurtles = 2 + 1

let numberOfHamsters = 1 + 1

let totalNumberOfAnimals = numberOfDogs + numberOfCats + numberOfTurtles + numberOfHamsters
let numberOfPotBelliedPig = 1

let totalNumberOfMammals = numberOfDogs + numberOfCats + numberOfHamsters
let numberOfFish = 1

let numberOfSnake = 1

let totalNumberOfAnimals = numberOfDogs + numberOfCats + numberOfTurtles + numberOfHamsters + numberOfPotBelliedPig + numberOfFish + numberOfSnake

let totalNumberOfMammals = numberOfDogs + numberOfCats + numberOfHamsters + numberOfPotBelliedPig

//: - experiment: There are even more changes in the pets expected at the pet show.\
//:To add new kinds of animals, add new lines of code that define new constants. (To add a new line of code just click on a blank line in the area above and start typing.)
Expand All @@ -27,3 +33,20 @@ let totalNumberOfMammals = numberOfDogs + numberOfCats + numberOfHamsters
//: Next, learn about choosing names.
//:
//:[Previous](@previous) | page 6 of 14 | [Next: Choosing Good Names](@next)
let numberOfDogs2 = 6 + 2

let numberOfCats2 = 5 - 1

let numberOfTurtles2 = 2 + 1

let numberOfHamsters2 = 1 + 1

let numberOfPotBelliedPig2 = 1

let numberOfFish2 = 1

let numberOfSnake2 = 1

let totalNumberOfAnimals2 = numberOfDogs + numberOfCats + numberOfTurtles + numberOfHamsters + numberOfPotBelliedPig + numberOfFish + numberOfSnake

let totalNumberOfMammals2 = numberOfDogs + numberOfCats + numberOfHamsters + numberOfPotBelliedPig
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
//: In Swift, you can choose a name and associate it with a value by defining a _constant_. You’ll explore constants in more detail later in the course. For now, it’s enough to know that constants are a fundamental way of naming values in Swift.
//:
//: Use the word `let` followed by a name to define a constant and the equal sign `=` to give a value to the constant:
let numberOfDogs = 6
let numberOfDogs = 6 + 2

let numberOfCats = 5
let numberOfCats = 4

let numberOfTurtles = 2
let numberOfTurtles = 3

let numberOfHamsters = 1
let numberOfHamsters = 2

//: After you’ve defined a constant and assigned a value to it, you can use the constant wherever you would have used the value, including in mathematical calculations that define the value of a new constant:

Expand All @@ -35,3 +35,14 @@ let totalNumberOfMammals = numberOfDogs + numberOfCats + numberOfHamsters
//: Once you’re finished experimenting, move ahead.
//:
//:[Previous](@previous) | page 4 of 14 | [Next: Typing Names and Autocompletion](@next)
let numberOfDogs2 = 6 + 2

let numberOfCats2 = 4

let numberOfTurtles2 = 3

let numberOfHamsters2 = 2

let totalNumberOfAnimals2 = numberOfDogs + numberOfCats + numberOfTurtles + numberOfHamsters

let totalNumberOfMammals2 = numberOfDogs + numberOfCats + numberOfHamsters
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,20 @@
//: Next you’ll find out how to do that.
//:
//:[Previous](@previous) | page 3 of 14 | [Next: Naming Things](@next)
// Number Of Dogs
6

// Number Of Cats
5

// Number Of Turtles
2

// Number Of Hamsters
1

// Total Number Of Animals
6 + 5 + 2 + 1

// Total Number Of Mammals
6 + 5 + 1
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,22 @@
//:
//: Using what you know so far, you could keep track of the count for each animal using a comment and a number, like this:
// Number Of Dogs
5
6

// Number Of Cats
4
5

// Number Of Turtles
3
2

// Number Of Hamsters
1
//: Then you could copy those numbers onto new lines of code and let the playground do some math for you, like this:
// Total Number Of Animals
5 + 4 + 3
6 + 5 + 2 + 1

// Total Number Of Mammals
5 + 4
6 + 5 + 1
//: - experiment: As the week goes on, you get more information about what pets will be in the show.\
//:Change the code above to update the totals.
//:
Expand All @@ -34,3 +37,20 @@
//: Could there be a better way to solve this problem? Think about it for a minute or two, then move on.
//:
//:[Previous](@previous) | page 2 of 14 | [Next: Pet Problem Recap](@next)
// Number Of Dogs
6

// Number Of Cats
5

// Number Of Turtles
2

// Number Of Hamsters
1

// Total Number Of Animals
6 + 5 + 2 + 1

// Total Number Of Mammals
6 + 5 + 1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<playground version='6.0' target-platform='ios' display-mode='rendered' executeOnSourceChanges='true'>
<playground version='6.0' target-platform='macos' display-mode='rendered' executeOnSourceChanges='true'>
<pages>
<page name='Introduction'/>
<page name='Pet Problem'/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,18 @@ let finishedMessage = username + " " + likesYourPostMessage
//:Combine your `firstName` and `likesYourPostMessage`\
//:Type each line of code below the relevant comment below.
// Declare a firstName constant

let FirstName = "mohammed"

// Declare a lastName constant

let LastName = "aloqbi"

// Combine the strings into a fullName constant

let fullName = FirstName + LastName

// Combine your first name with likesYourPostMessage
let LikesYourNameMessage = "wow"

let textMessage = FirstName + " " + LikesYourNameMessage

//: Next, find out how building strings by adding them can get complicated.
//:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@ let heightInCentimeters = 7817
let favoriteBook = "The Sun Also Rises"

let traditionalGreeting = "Hello, world!"
//: The declared string values also appear in the results sidebar. 👉
//: - experiment: Practice by declaring `favoriteMovie` and `favoriteSong` string constants for your favorite movie and song:
// Declare a favoriteMovie constant


// Declare a favoriteSong constant


//: Next, take a string-based trip around the world.
//:
//:[Previous](@previous) | page 3 of 16 | [Next: Unicode](@next)
// Declare a favoriteMovie constant
let favouriteMovie = "Schindler's List"

// Declare a favoriteSong constant
let favouriteSong = "Hozier-Movement"
Loading