Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
48 views
2 pages
Week 1 Python
Uploaded by
Karthik Thippirisetti
AI-enhanced title
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Download
Save
Save week 1 python For Later
Share
0%
0% found this document useful, undefined
0%
, undefined
Print
Embed
Report
0 ratings
0% found this document useful (0 votes)
48 views
2 pages
Week 1 Python
Uploaded by
Karthik Thippirisetti
AI-enhanced title
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Carousel Previous
Carousel Next
Download
Save
Save week 1 python For Later
Share
0%
0% found this document useful, undefined
0%
, undefined
Print
Embed
Report
Download
Save week 1 python For Later
You are on page 1
/ 2
Search
Fullscreen
Instantly share code, notes, and snippets AnOnYm0us001100 / course_4_assessment_1.py Created 3 years ago WY Star © Code © Revisions 1 ‘course_4_assessment_1 of Python Classes and Inheritance under Python 3 Specialization offered by Coursera El course 4 assessuent apy 10 a 2 a Pa 6 16 wv 18 » 20 a 2 23 24 2s 26 a 28 29 30 31 22 #1/usr/oin/env python # coding: utf-8 1. Define a class called Bike that accepts a string and a float as input, and assigns those inputs re to two instance variables, color and price. Assign to the variable testOne an instance of Bike whose blue and whose price is 89.99. Assign to the variable testTwo an instance of Bike whose color is purp whose price is 25.0. class ike def _init_(self,st,1) self.color = st self.price = fl testone = Bike("blue”,89.99) testIwo = Bike("purple",25.0) print (testone) print (testTwo) 2, Create a class called AppleBasket whose constructor accepts tho inputs: a string representing a co land a nunber representing a quantity of apples. The constructor should initialize tio instance variab apple_color and apple_quantity. Write 2 class method called increase that increases the quantity by 1 time ie Ls Invoked. You should also write a _str__ method for this class that returns a string of th ‘A basket of [quantity goes here] [color goes here] apples." e.g. “A basket of 4 red apples." or "Ab 5@ blue apples." (Writing sone test code that creates instances and assigns values to variables may h solve this problen!) class AppleBasket def _init_(self,c,a) self.apple_color = ¢33 34 35 36 7 38 39 40 a a2 a aa 45 46 a7 48 49 50 st 52 53 sa 55 56 s7 58 59 self.apple_quantity = q def increase(self): self.apple_quantity ¢= 1 def _str_(self): return "A basket of {} {} apples.".fornat(self.apple_quantity, self. apple_color) a = Applefasket (“red*,4) print (a) 3. Define a class called BankAccount that accepts the name you want associated with your bank account string, and an integer that represents the anount of money in the account. The constructor should ini two instance variables fron those inputs: name and amt. Add a string method so that when you print an of BankAccount, you see “Your account, [name goes here], has [start_ant goes here] dollars create an instance of this class with "Bob" as the name and 100 as the amount. Save this to the varia class SankAccount def _init__(self,name,ant) self.nane = name self.ant = ant def _str_(sel#): return "Your account, {}, has {} dollars.".fornat(self.name, self ant) tL = BankAccount(“Bob",120) print (t1)
You might also like
Uday Sir
PDF
No ratings yet
Uday Sir
69 pages
Object Oriented Programming Introduction in Python
PDF
No ratings yet
Object Oriented Programming Introduction in Python
80 pages
Python Course
PDF
No ratings yet
Python Course
97 pages
Introduction To Python Programming (OOP Inheritance)
PDF
No ratings yet
Introduction To Python Programming (OOP Inheritance)
23 pages
Python
PDF
No ratings yet
Python
64 pages
Python OOP Concepts
PDF
No ratings yet
Python OOP Concepts
16 pages
Python OOPS Concepts
PDF
No ratings yet
Python OOPS Concepts
18 pages
07python Classes
PDF
No ratings yet
07python Classes
52 pages
3-2 CRT Python Examples
PDF
No ratings yet
3-2 CRT Python Examples
24 pages
CAP776OOPS
PDF
No ratings yet
CAP776OOPS
86 pages
OOPS Python
PDF
No ratings yet
OOPS Python
26 pages
ENGR 101 Introduction To Programming: Week 13
PDF
No ratings yet
ENGR 101 Introduction To Programming: Week 13
28 pages
Python Classes
PDF
No ratings yet
Python Classes
23 pages
04 Four
PDF
No ratings yet
04 Four
19 pages
Python Classes: Class
PDF
No ratings yet
Python Classes: Class
24 pages
Scenario Based Question For Python-Unit 2
PDF
No ratings yet
Scenario Based Question For Python-Unit 2
21 pages
Project File Cse
PDF
No ratings yet
Project File Cse
162 pages
Wa0006
PDF
No ratings yet
Wa0006
20 pages
Python Practical Unit 3 Final
PDF
No ratings yet
Python Practical Unit 3 Final
18 pages
Python Programming
PDF
No ratings yet
Python Programming
17 pages
Assignment 6
PDF
No ratings yet
Assignment 6
12 pages
CW Lab 23u02116 Shankar
PDF
No ratings yet
CW Lab 23u02116 Shankar
31 pages
CW Lab 23U02122 Ayush
PDF
No ratings yet
CW Lab 23U02122 Ayush
31 pages
Python Lab Assignment 4
PDF
No ratings yet
Python Lab Assignment 4
19 pages
Unit 3
PDF
No ratings yet
Unit 3
31 pages
Ns Python
PDF
No ratings yet
Ns Python
12 pages
Exp10 PPJ
PDF
No ratings yet
Exp10 PPJ
14 pages
Python U-3 Practical Gujarat University
PDF
No ratings yet
Python U-3 Practical Gujarat University
22 pages
Classyobjects Answers
PDF
No ratings yet
Classyobjects Answers
9 pages
2024 25 COL100 Lab 11 Class Object
PDF
No ratings yet
2024 25 COL100 Lab 11 Class Object
14 pages
Lecture 25
PDF
No ratings yet
Lecture 25
14 pages
PRG6
PDF
No ratings yet
PRG6
8 pages
Lab 9 Submission PPJ
PDF
No ratings yet
Lab 9 Submission PPJ
10 pages
Oops Hands - On
PDF
No ratings yet
Oops Hands - On
10 pages
Python Unit 2
PDF
No ratings yet
Python Unit 2
15 pages
Python Oops by Rohit Verma Ai Engineer
PDF
No ratings yet
Python Oops by Rohit Verma Ai Engineer
9 pages
Python Cheatsheet Geetika
PDF
No ratings yet
Python Cheatsheet Geetika
26 pages
9-14 Ap
PDF
No ratings yet
9-14 Ap
5 pages
Do68 Rahulsinha Experiment10
PDF
No ratings yet
Do68 Rahulsinha Experiment10
5 pages
Abhishek Assignment 3
PDF
No ratings yet
Abhishek Assignment 3
5 pages
PYTHON
PDF
No ratings yet
PYTHON
6 pages
Experiment No.07: Part A
PDF
No ratings yet
Experiment No.07: Part A
6 pages
Lab 11 Output
PDF
No ratings yet
Lab 11 Output
3 pages
Practiceset 2
PDF
No ratings yet
Practiceset 2
5 pages
Ex 09
PDF
No ratings yet
Ex 09
4 pages
Session5 Notes-1
PDF
No ratings yet
Session5 Notes-1
7 pages
Module01 Wk02a Classes
PDF
No ratings yet
Module01 Wk02a Classes
14 pages
OOPs
PDF
No ratings yet
OOPs
4 pages
Python Cheat Sheet
PDF
No ratings yet
Python Cheat Sheet
12 pages
OOPS
PDF
No ratings yet
OOPS
4 pages
Python Cheat Sheet
PDF
No ratings yet
Python Cheat Sheet
9 pages
Class Object Init Self Examples
PDF
No ratings yet
Class Object Init Self Examples
3 pages
Day - 14 Assignment Solutions
PDF
No ratings yet
Day - 14 Assignment Solutions
6 pages
As 5
PDF
No ratings yet
As 5
4 pages
Python Cheat Sheet
PDF
No ratings yet
Python Cheat Sheet
9 pages
Classes in Python
PDF
No ratings yet
Classes in Python
5 pages
Ir Sensor
PDF
No ratings yet
Ir Sensor
13 pages
3
PDF
No ratings yet
3
1 page
Ai Based Robot For Shoreline Cleaning
PDF
No ratings yet
Ai Based Robot For Shoreline Cleaning
2 pages
Svce Ece3
PDF
No ratings yet
Svce Ece3
3 pages