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)
45 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
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
0 ratings
0% found this document useful (0 votes)
45 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
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
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
Python Course
PDF
No ratings yet
Python Course
97 pages
Object Oriented Programming Introduction in Python
PDF
No ratings yet
Object Oriented Programming Introduction in Python
80 pages
Python
PDF
No ratings yet
Python
64 pages
3-2 CRT Python Examples
PDF
No ratings yet
3-2 CRT Python Examples
24 pages
Scenario Based Question for Python-unit 2
PDF
No ratings yet
Scenario Based Question for Python-unit 2
21 pages
Ns Python
PDF
No ratings yet
Ns Python
12 pages
Python programming
PDF
No ratings yet
Python programming
17 pages
04 Four
PDF
No ratings yet
04 Four
19 pages
as5
PDF
No ratings yet
as5
4 pages
OOPs
PDF
No ratings yet
OOPs
4 pages
Uday Sir
PDF
No ratings yet
Uday Sir
69 pages
Wa0006
PDF
No ratings yet
Wa0006
20 pages
classyObjects_answers
PDF
No ratings yet
classyObjects_answers
9 pages
PYTHON (1)
PDF
No ratings yet
PYTHON (1)
6 pages
PRG6
PDF
No ratings yet
PRG6
8 pages
3
PDF
No ratings yet
3
1 page
Python Classes
PDF
No ratings yet
Python Classes
23 pages
Class_Object_Init_Self_Examples
PDF
No ratings yet
Class_Object_Init_Self_Examples
3 pages
Oops Hands - On
PDF
No ratings yet
Oops Hands - On
10 pages
ENGR 101 Introduction To Programming: Week 13
PDF
No ratings yet
ENGR 101 Introduction To Programming: Week 13
28 pages
Ai Based Robot for Shoreline Cleaning
PDF
No ratings yet
Ai Based Robot for Shoreline Cleaning
2 pages
07python_classes(1)
PDF
No ratings yet
07python_classes(1)
52 pages
2330293Lab9SubmissionPPJ
PDF
No ratings yet
2330293Lab9SubmissionPPJ
10 pages
Ir sensor
PDF
No ratings yet
Ir sensor
13 pages
07python Classes(1)
PDF
No ratings yet
07python Classes(1)
36 pages
2024_25_COL100_Lab_11_Class_Object (1)
PDF
No ratings yet
2024_25_COL100_Lab_11_Class_Object (1)
14 pages
2330376 EXP10 PPJ
PDF
No ratings yet
2330376 EXP10 PPJ
14 pages
lab 11 output
PDF
No ratings yet
lab 11 output
3 pages
Session5 Notes-1
PDF
No ratings yet
Session5 Notes-1
7 pages
Python Lab Assignment 4
PDF
No ratings yet
Python Lab Assignment 4
19 pages
Do68 Rahulsinha Experiment10
PDF
No ratings yet
Do68 Rahulsinha Experiment10
5 pages
Practiceset 2
PDF
No ratings yet
Practiceset 2
5 pages
9-14 Ap
PDF
No ratings yet
9-14 Ap
5 pages
OOP Programs
PDF
No ratings yet
OOP Programs
19 pages
Abhishek Assignment 3
PDF
No ratings yet
Abhishek Assignment 3
5 pages
Svce Ece3
PDF
No ratings yet
Svce Ece3
3 pages
Python OOPS concepts
PDF
No ratings yet
Python OOPS concepts
18 pages
Ex-09
PDF
No ratings yet
Ex-09
4 pages
Lecture 25
PDF
No ratings yet
Lecture 25
14 pages
Experiment No.07: Part A
PDF
No ratings yet
Experiment No.07: Part A
6 pages
OOPS Python
PDF
No ratings yet
OOPS Python
26 pages
Python Oops by Rohit Verma Ai Engineer
PDF
No ratings yet
Python Oops by Rohit Verma Ai Engineer
9 pages
Unit 3
PDF
No ratings yet
Unit 3
31 pages
CW_Lab_23U02122_Ayush
PDF
No ratings yet
CW_Lab_23U02122_Ayush
31 pages
Module01 Wk02a Classes
PDF
No ratings yet
Module01 Wk02a Classes
14 pages
CAP776OOPS
PDF
No ratings yet
CAP776OOPS
86 pages
Assignment 6
PDF
No ratings yet
Assignment 6
12 pages
Python Cheatsheet Geetika
PDF
No ratings yet
Python Cheatsheet Geetika
26 pages
Day - 14 Assignment solutions
PDF
No ratings yet
Day - 14 Assignment solutions
6 pages
CW_Lab_23u02116_Shankar
PDF
No ratings yet
CW_Lab_23u02116_Shankar
31 pages
Python Unit 2
PDF
No ratings yet
Python Unit 2
15 pages
Python U-3 Practical Gujarat University
PDF
No ratings yet
Python U-3 Practical Gujarat University
22 pages
OOPS
PDF
No ratings yet
OOPS
4 pages
Python Classes: Class
PDF
No ratings yet
Python Classes: Class
24 pages
Python Cheat Sheet
PDF
No ratings yet
Python Cheat Sheet
9 pages
Python Cheat Sheet
PDF
No ratings yet
Python Cheat Sheet
12 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
Project File Cse
PDF
No ratings yet
Project File Cse
162 pages
Introduction To Python Programming (OOP Inheritance)
PDF
No ratings yet
Introduction To Python Programming (OOP Inheritance)
23 pages