In [ ]: #this code will add two number
#input
number1=56
number2=6321
#processing
total=number1+number2
#output
print('the numbers that were added ', number1, number2)
print('The total of the addition :', total)
Problem: Add two numbers and show the result
In [ ]: #adding a comment would help
#input
myMoney=333
yourMoney=444
#processing
thetotal=myMoney+yourMoney
#output
print('The value money is:', thetotal)
Ask for input and show output and add comments
In [ ]: #this program add the number of masks
#input
nNum1=int(input('Please a number: '))
nNum2=int(input('Please another number: '))
#processing
nTotal=nNum1+nNum2
#output
print('The value is:', nTotal)
A problem that is more detailed, with comments, input, process
and output
, In [ ]: #This is comment
nNumber1=int(input('Please enter the number of learners in the school : '))
nNumber2=int(input('Please enter the number of educators in the school : '))
#this is the processing
nTotal= nNumber1+nNumber2
#this is the output
print('The total number of people at school is : ', nTotal)
Changing from adding to other operations
In [ ]: #How many books does each learner receive?
#This is the input
a=int(input('Please enter the number of books issued to the school : '))
b=int(input('Please enter the number of learners in the school: '))
#this is the processing
thetotal=a//b
theremain=a%b
#this is the output
print('The value is:', thetotal)
print('The remainder is:', theremain)
Changing multiple. Change the data type?
In [ ]: #calculate the area of a rectangle
#input
length=int(input('Please enter the length of the rectangle: '))
breadth=float(input('Please enter the breadth of the rectangle: '))
#process
area=length*breadth
#output
print('The area in square meters is:', area)
In [ ]: #calcuate the area of a triangle.
#ask the user for input values
base=int(input('Please enter the base length (m): '))
height=int(input('Please enter the height (m): '))
areatri=0.5*base*height
print('Area is (in square meters) : ', areatri)
Add the marks that you received for 4 assignments, and calcuate
the average value
In [ ]:
, Using a number to a power
In [ ]: a=2
b=5
thepower=a**b
print(thepower)
Use the radius of a wheel to calcuate the circumference of the
wheel
In [ ]:
Calculate the speed. Ask for user input in km and hours. Format
the output in km/h to two decimal values.
In [ ]:
Determine the data type of a variable. Ask for user input for
integer, float and string.
In [ ]: a=21
print(type(a))
In [ ]:
The benefits of buying summaries with Stuvia:
Guaranteed quality through customer reviews
Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.
Quick and easy check-out
You can quickly pay through EFT, credit card or Stuvia-credit for the summaries. There is no membership needed.
Focus on what matters
Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!
Frequently asked questions
What do I get when I buy this document?
You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.
Satisfaction guarantee: how does it work?
Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.
Who am I buying this summary from?
Stuvia is a marketplace, so you are not buying this document from us, but from seller PotatoArmor. Stuvia facilitates payment to the seller.
Will I be stuck with a subscription?
No, you only buy this summary for R50,00. You're not tied to anything after your purchase.