Explain how python programs are structured and give an example of how methods are initiated

Python programs like most declarative programming languages are made up of small subroutines called "methods". To set-up an example program, you need to define a method (eg. def someMethod(): ) and then specify what you want that method to do. For example, it could print something to the console (like: print("Hello World!")) or it could perform a sequence of steps (aka an algorithm). In order to run the program, you need to declare the method in a separate section of the program (i.e. outside of the method you've defined) - typically in a main method (def main():) and then a declaration is needed to initialise the main method (if name = "main":).

Answered by Prince Omanami W. Python tutor

1038 Views

See similar Python Mentoring tutors

Related Python Mentoring answers

All answers ▸

Write a program that can convert between celcius and farenheit temperature scales


Sales is real Customers is integer startmainprog input Sales input Customers if ((Sales > 500) OR ((Sales > 300) AND (Customers>9))) then output “Bonus Awarded” else output “No Bonus” end if end subroutine. Sales = 600 Customers = 9, answer:


Firstly, my question is not Python related, but maths A-level related. I don't know how to change that in my profile but I would like to only tutor maths GCSE and potentially A-level. My question: Integrate sin(x)^3 over x=0 and x=pi/2.


Given a list of N numbers, use a single list comprehension to produce a new list that only contains those values that are: (a) even numbers, and (b) from elements in the original list that had even indices .


We're here to help

contact us iconContact usWhatsapp logoMessage us on Whatsapptelephone icon+44 (0) 203 773 6020
Facebook logoInstagram logoLinkedIn logo

© MyTutorWeb Ltd 2013–2024

Terms & Conditions|Privacy Policy