<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[It's My show]]></title><description><![CDATA[It's My show]]></description><link>https://aryalashok.com.np</link><generator>RSS for Node</generator><lastBuildDate>Thu, 09 Apr 2026 09:51:29 GMT</lastBuildDate><atom:link href="https://aryalashok.com.np/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Object Attributes]]></title><description><![CDATA[Problem Description
Write a program to create a class and print attributes using a method of the class.
Create a class

Create a class named Bicycle.

Inside this class, create two methods named: __init__() and print_attributes().

The class will hav...]]></description><link>https://aryalashok.com.np/object-attributes</link><guid isPermaLink="true">https://aryalashok.com.np/object-attributes</guid><dc:creator><![CDATA[Ashok Aryal]]></dc:creator><pubDate>Sun, 08 Dec 2024 15:48:13 GMT</pubDate><content:encoded><![CDATA[<h2 id="heading-problem-description"><strong>Problem Description</strong></h2>
<p>Write a program to create a class and print attributes using a method of the class.</p>
<p><strong>Create a class</strong></p>
<ul>
<li><p>Create a class named <code>Bicycle</code>.</p>
</li>
<li><p>Inside this class, create two methods named: <code>__init__()</code> and <code>print_attributes()</code>.</p>
</li>
<li><p>The class will have two attributes: <code>gear</code> and <code>speed</code> which should be initialized inside <code>__init__()</code>.</p>
</li>
<li><p>Inside the <code>print_attributes()</code> method, print the <code>gear</code> attribute followed by the <code>speed</code> attribute in two separate lines.</p>
</li>
</ul>
<p><strong>Outside of the class</strong></p>
<ul>
<li><p>Create an object named <code>bicycle1</code> of the <code>Bicycle</code> class. The <code>gear</code> and <code>speed</code> attributes of this object should be <strong>4</strong> and <strong>80</strong> respectively.</p>
</li>
<li><p>Call the <code>print_attributes()</code> method using the <code>bicycle1</code> object.</p>
</li>
</ul>
<pre><code class="lang-python"><span class="hljs-comment"># create the class</span>
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Bicycle</span>:</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">__init__</span>(<span class="hljs-params">self, gear, speed</span>):</span>
        <span class="hljs-comment"># initialize attributes</span>
        self.gear = gear
        self.speed = speed

    <span class="hljs-comment"># create the print_attributes() method </span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">print_attributes</span>(<span class="hljs-params">self</span>):</span>
        print(self.gear)
        print(self.speed)

<span class="hljs-comment"># create the object with 4 and 80 as arguments</span>
bicycle1 = Bicycle(<span class="hljs-number">4</span>,<span class="hljs-number">80</span>)

<span class="hljs-comment"># call print_attributes() using bicycle1</span>
bicycle1.print_attributes()
</code></pre>
]]></content:encoded></item></channel></rss>