×

### Let's log you in.

or

Don't have a StudySoup account? Create one here!

×

or

9

0

5

# Week 3 Csc 127A/110 CSC 127A - 002

UA

Get a free preview of these Notes, just enter your email below.

×
Unlock Preview

Week 3 CSC Notes
COURSE
Introduction to Computer Science
PROF.
Allison Osbourn
TYPE
Class Notes
PAGES
5
WORDS
CONCEPTS
Computer Science
KARMA
25 ?

## Popular in Computer Science and Engineering

This 5 page Class Notes was uploaded by Kate Jahaske on Friday September 9, 2016. The Class Notes belongs to CSC 127A - 002 at University of Arizona taught by Allison Osbourn in Fall 2016. Since its upload, it has received 9 views. For similar materials see Introduction to Computer Science in Computer Science and Engineering at University of Arizona.

×

## Reviews for Week 3 Csc 127A/110

×

×

### What is Karma?

#### You can buy or earn more Karma at anytime and redeem it for class notes, study guides, flashcards, and more!

Date Created: 09/09/16
Week 3, 9/9/16 Sizing for the car drawing: 1. from drawingpanel import * 2. 3. def main(): 4. p = DrawingPanel(300, 100, background="light gray") 5. 6. draw_car(p, 10, 30, 100) # (pannel, x, y, size) 7. draw_car(p, 150, 10, 50) 8. 9. def draw_car(p, x, y, size): # size = 100 10. 11. p.canvas.create_rectangle(x, y, x + size, y + size / 2, fill="black") # trying to get size to equal 100 for x and 50 for y 12. p.canvas.create_oval(x + size / 10, y + size / 10 * 4, x + size / 10 * 3, y + size / 10 * 6, fill="red", width=0) 13. p.canvas.create_oval(x + size / 10 * 7, y + size / 10 * 4, x + size / 10 * 9, y + size / 10 * 6, fill="red", width=0) 14. p.canvas.create_rectangle(x + size / 10 * 7, y + size / 10, x + size, y + size / 10 * 3, fill="cyan", width=0) 15. 16. main() Note* make sure you hit enter to continue your string on the next line, they cannot go over 100 characters. Drawing panel must be in the same file as python to be able to import. However, math import is built into python and nothing extra is needed to be downloaded. It is necessary to use from math import * to use the specific math functions listed in the slides. Simply calling a Python math function does not produce a visible result, to produce a visible output you must turn it into a variable: 17. from math import * 18. 19. def main(): 20. 21. result = floor(7.1) 22. print(result) 23. 24. main() The math functions min and max can be used to bound numbers. For example with an age, no one can be –3. For example, (0, -8) use the max function, as max will never be less than 0.  max (0, -5) To create a cap, use the min function. I.e. min(90, 104) will always select the lowest number, which can never be above the range we set as 90.  min (90, 104) The computer can represent numbers in an imprecise way;  I.e. 0.2 + 0.1 = 0.30000000004 Type cast: a conversion from one type to another. This will truncate a double from a real number to an integer Two parts to a return function:  Writing a function that returns  Actually calling the function A slope function only exists within itself. It will replace slope anywhere in your program with what slope equals. Instead, designate a variable and call slope within the variable. I.e 25. main() 26. 27. s= slope (0, 0, 6, 3) # use a variable instead of simply 28. 29. def slope(x1, x2, y1, y2) 30. dy = y2 - y1 31. dx = x2 - y1 32. return = dy / dx 33. return = result Displacement: 34. from math import * 35. 36. def main(): 37. result = floor(3 * 10) 38. print(result) 39. displacement(3.0, 4.0, 5.0) 40. print(result) # two prints are needed to return displacement as well as floor 41. 42. def displacement(v, a, t): 43. disp = v * t + 0.5 * a * t ** 2 44. return disp 45. 46. main() 9/7/16 Use drawing panel provided on class website. To use drawing panel use: from drawingpanel import * See the powerpoint for named colors. You can use your own colors using a hex. I.e. #(6numbers). 1. from drawingpanel import * 2. 3. def main(): 4. panel = DrawingPanel (200, 300, background="#990055) # x is width, y is height. Colors can be named or a hex 5. 6. main() If you would like to draw something, use your "canvas." Each (x, y) position is a pixel (or dot on a plot.)  panel.canvas.create_line(x1, y1,x2, y2, fill =)  panel.canvas.create_line(0, 0, 200, 200, fill = white) # this will print out a line To draw an oval, your computer will take the two points you specify, and will make the biggest oval in between the box without touching any points.  panel.canvas.create_oval(50, 50, 100, 200, outline="yellow", width=0) not filled in  panel.canvas.create_oval(50, 50, 100, 200, fill="yellow", width=0) filled in with a black outline. Black is the default outline  panel.canvas.create_oval(50, 50, 100, 200, outline="yellow", fill="yellow", width=0) filled in with a yellow outline You can also create_rectangle and create_text (which will print a string). 7. # Draw ten stacked rectangles starting at 20, 20, height 10, width starting at 100 and decreasing by 10 each time. 8. from drawingpanel import * 9. panel = DrawingPanel(160, 160) 10. 11. for i in range(0, 10): 12. panel.canvas.create_rectangle(20, 20 + 10 * i, 120 - 10 * i, 30 + 10 * i) 13. 14. # 120 is the coordinate at the end of the uppermost rectangle 15. # x1, y1, is the upper left coordinate 16. # x2, y2 is the lower right coordinate 17. # y = up and down 18. # x = right to left 19. from drawingpanel import * 20. 21. def main(): 22. p = DrawingPanel(300, 100, background="light gray") # make sure this is in main, and not the function otherwise you will print two panels 23. draw_car(p, 10, 30) 24. draw_car(p, 150, 10) 25. 26. for i in range(0, 30): 27. draw_car(p, i * 30, 100) 28. p.sleep() # sleep will delay the output 29. p.canvas.create_rectangle(0, 0, 500, 200, fill="light gray") # to erase the extra delay in the output 30. 31. def draw_car(p, x, y): 32. 33. p.canvas.create_rectangle(x, y, x+ 100, y + 50, fill="black") # remember to change both coordinates to your parameters 34. 35. p.canvas.create_oval(x + 10, y + 40, x + 30, y + 60, fill="red", width=0) # in the parameter, x = 10. To get 20 for the first value, use 20 - 10. 36. p.canvas.create_oval(x + 70, y + 40, x + 90, y + 60, fill="red", width=0) 37. 38. p.canvas.create_rectangle(x + 70, y + 10, x + 100, y + 30, fill="cyan", width=0) 39. 40. main()

×

×

### BOOM! Enjoy Your Free Notes!

×

Looks like you've already subscribed to StudySoup, you won't need to purchase another subscription to get this material. To access this material simply click 'View Full Document'

## Why people love StudySoup

Steve Martinelli UC Los Angeles

#### "There's no way I would have passed my Organic Chemistry class this semester without the notes and study guides I got from StudySoup."

Allison Fischer University of Alabama

#### "I signed up to be an Elite Notetaker with 2 of my sorority sisters this semester. We just posted our notes weekly and were each making over \$600 per month. I LOVE StudySoup!"

Bentley McCaw University of Florida

#### "I was shooting for a perfect 4.0 GPA this semester. Having StudySoup as a study aid was critical to helping me achieve my goal...and I nailed it!"

Parker Thompson 500 Startups

#### "It's a great way for students to improve their educational experience and it seemed like a product that everybody wants, so all the people participating are winning."

Become an Elite Notetaker and start selling your notes online!
×

### Refund Policy

#### STUDYSOUP CANCELLATION POLICY

All subscriptions to StudySoup are paid in full at the time of subscribing. To change your credit card information or to cancel your subscription, go to "Edit Settings". All credit card information will be available there. If you should decide to cancel your subscription, it will continue to be valid until the next payment period, as all payments for the current period were made in advance. For special circumstances, please email support@studysoup.com

#### STUDYSOUP REFUND POLICY

StudySoup has more than 1 million course-specific study resources to help students study smarter. If you’re having trouble finding what you’re looking for, our customer support team can help you find what you need! Feel free to contact them here: support@studysoup.com

Recurring Subscriptions: If you have canceled your recurring subscription on the day of renewal and have not downloaded any documents, you may request a refund by submitting an email to support@studysoup.com