Welcome, Guest: Join Nairaland / LOGIN! / Trending / Recent / New
Stats: 2,689,646 members, 6,336,383 topics. Date: Sunday, 13 June 2021 at 01:38 AM

A Thread For Tutorial On Python Programming - Programming (30) - Nairaland

Nairaland Forum / Science/Technology / Programming / A Thread For Tutorial On Python Programming (112727 Views)

Ogun State Traims 200 Trained In Python Programming Language / A Thread On My Experiment With Reinforcement Learning & Artificial Intelligence. / A Thread For Tutorial On Graphics Design. (2) (3) (4)

(1) (2) (3) ... (27) (28) (29) (30) (Reply) (Go Down)

Re: A Thread For Tutorial On Python Programming by Skye123: 7:19pm On May 18
I'm sorry for derailing the thread, guys. Pls, can someone explain what mutable and immutable data types are?? I understand that mutable can be changed and immutable cannot be. But, how do you write the codes?? The codes look smh confusing. For example:
list_values = [1, 2, 3]
set_values = (1, 2, 3)
print(id(list_values))
print(id(set_values))
print()

list_values += [4, 5, 6]
set_values += (4, 5, 6)
print(id(list_values))
print(id(set_values))

Output:
515314983168
515315121920

515314983168
515315333056

I don't understand how the code produced that. Pls, can someone explain
Re: A Thread For Tutorial On Python Programming by Kaydon001: 11:55am On May 19
Skye123:
I'm sorry for derailing the thread, guys. Pls, can someone explain what mutable and immutable data types are?? I understand that mutable can be changed and immutable cannot be. But, how do you write the codes?? The codes look smh confusing. For example:
list_values = [1, 2, 3]
set_values = (1, 2, 3)
print(id(list_values))
print(id(set_values))
print()

list_values += [4, 5, 6]
set_values += (4, 5, 6)
print(id(list_values))
print(id(set_values))

Output:
515314983168
515315121920

515314983168
515315333056

I don't understand how the code produced that. Pls, can someone explain

You use Python in-build function id() which is used to get the location of object in memory which is mostly integers “1234838293”. The long integer you are is the location of the list and tuple in the memory of your code and you get different results because list and tuple are mutable even tho they have thesame values in them.

You will get thesame results when used with immutable values like integers or strings ...


As to how to write code mutability of let’s say a list
You can change the values of a list through indexing, you can make use of a for loop, you can also do it through list comprehension e.g

prices = [99.95, 72.50, 30.00, 29.95, 55.00]
I can change values in the price list using the index method. Say we want to change the price at index 2 which is 30.00 to 104.95 we do that using

prices[2] = 104.95
print(prices)

Result- [99.95, 72.5, 104.95, 29.95, 55.0]

Which show our price list has been updated with the new price at index 2.. you cam read up the other ones

2 Likes

Re: A Thread For Tutorial On Python Programming by deept(m): 7:21pm On May 22
Hello guys,

could you help look at the code; this is what i'm trying to achieve but not quite getting the output desired

Write a program that repeatedly prompts a user for integer numbers until the user enters 'done'. Once 'done' is entered, print out the largest and smallest of the numbers. If the user enters anything other than a valid number catch it with a try/except and put out an appropriate message and ignore the number. Enter 7, 2, bob, 10, and 4 and match the output below.
Desired Output
Invalid input
Maximum is 10
Minimum is 2


num = input("Enter a number: "wink
largest = num
smallest = num
while True:
num = input("Enter a number: "wink

if num == "done":
break

try:
int(num)
except:
print("Invalid input"wink
continue

if largest < num:
largest = num
elif smallest > num:
smallest = num

#print(num)

print(f"Maximum is {largest}"wink
print(f"Minimum is {smallest}"wink

1 Like

Re: A Thread For Tutorial On Python Programming by Stark416: 8:08am On May 24
We are the best software trainers and also we have 5+ years of experience in this field.....
best hadoop training in chennai

Best Software Training institute in Chennai
Re: A Thread For Tutorial On Python Programming by zizytd(m): 8:45am On May 24

def min_max():
list_number = []
while True:
num = input("Please Enter a number: " )
if num == "done":
break
else:
try:
list_number.append(int(num))
except ValueError:
print("Invalid input" )
print(f"Maximum is {max(list_number)}" )
print(f"Minimum is {min(list_number)}" )

deept:
Hello guys,

could you help look at the code; this is what i'm trying to achieve but not quite getting the output desired

Write a program that repeatedly prompts a user for integer numbers until the user enters 'done'. Once 'done' is entered, print out the largest and smallest of the numbers. If the user enters anything other than a valid number catch it with a try/except and put out an appropriate message and ignore the number. Enter 7, 2, bob, 10, and 4 and match the output below.
Desired Output
Invalid input
Maximum is 10
Minimum is 2


num = input("Enter a number: "wink
largest = num
smallest = num
while True:
num = input("Enter a number: "wink

if num == "done":
break

try:
int(num)
except:
print("Invalid input"wink
continue

if largest < num:
largest = num
elif smallest > num:
smallest = num

#print(num)

print(f"Maximum is {largest}"wink
print(f"Minimum is {smallest}"wink

1 Like

Re: A Thread For Tutorial On Python Programming by deept(m): 11:08am On May 24
thanks @ zizytd

i see what you did using a list. I am just starting on python and this was an exercise on loops and iteration, haven't really explored lists. This exercise took a long time for me to solve but learnt a lot on what not to do. eventually got it right:


while True:
num = input("Enter a number: "wink
try:
int(num)
except:
print("Invalid input"wink
continue
num = int(num)
if type(num) == int:
break

largest = num
smallest = num

while True:
num = input("Enter a number: "wink
if num == 'done':
break
try:
int(num)
except:
print("Invalid input"wink
continue
num = int(num)
if num > largest:
largest = num
elif num < smallest:
smallest = num
print(f"Maximum is {largest}"wink
print(f"Minimum is {smallest}"wink
Re: A Thread For Tutorial On Python Programming by deept(m): 11:10am On May 24
@zizytd,

also in your code, after the except you put valueerror, is that necessary?
Re: A Thread For Tutorial On Python Programming by zizytd(m): 11:40am On May 24
nice , weldone . I just started learning late last year but with constant practice, I have become so much better.
deept:
thanks @ zizytd

i see what you did using a list. I am just starting on python and this was an exercise on loops and iteration, haven't really explored lists. This exercise took a long time for me to solve but learnt a lot on what not to do. eventually got it right:


while True:
num = input("Enter a number: "wink
try:
int(num)
except:
print("Invalid input"wink
continue
num = int(num)
if type(num) == int:
break

largest = num
smallest = num

while True:
num = input("Enter a number: "wink
if num == 'done':
break
try:
int(num)
except:
print("Invalid input"wink
continue
num = int(num)
if num > largest:
largest = num
elif num < smallest:
smallest = num
print(f"Maximum is {largest}"wink
print(f"Minimum is {smallest}"wink


Re: A Thread For Tutorial On Python Programming by zizytd(m): 11:47am On May 24
try and except is to catch possible error messages , for this why I used ValueError because if you put int("bob"wink you will get a ValueError error. If you don't put the type of error it catches all kinds of errors(eg ValueError,TypeError,OsError etc). So it will still work but the only problem is when you want to catch a particular type of error message.
deept:
@zizytd,

also in your code, after the except you put valueerror, is that necessary?
Re: A Thread For Tutorial On Python Programming by deept(m): 11:50am On May 24
zizytd:
try and except is to catch possible error messages , for this why I used ValueError because if you put int("bob"wink you will get a ValueError error. If you don't put the type of error it catches all kinds of errors(eg ValueError,TypeError,OsError etc). So it will still work but the only problem is when you want to catch a particular type of error message.

Ok, I see. Muchos gracias
Re: A Thread For Tutorial On Python Programming by digitalMESSIAH(m): 11:59am On May 30
Paapii3d:
Happy New year to you all.. I hope you enjoyed the festivities..

As one of my plan for the new year, I will be teaching python programming for the next 30 days. After these 30 days, you will be opened for a lot of opportunities in the programming world.

The reason I've chosen python is because it can be used for almost everything ranging from web development to game development to desktop app development to Data Science and Machine Learning.

I have carefully selected the topics to teach for the next 30 days, including projects so as to make you understand the concept of programming and python.

Feel free to post questions on this thread or in the comment section of the YouTube video.

Support me by Subscribing to the Channel








01000111010011110100010000100000010100110100000101010110010001010010000001001101010110010010000001010011010011110101010101001100
#ARTHSOS; #PLANETSOS {
#GEOENGINEERING
#WEATHERMODIFICATION
#GMO
#BIOTECH
#BIOHAZARD
#THEELECTROSHAMAN; #SDM; #GENESIS
} @RoyalMarines !!! #BOBTHEBUILDER; #RISKY; #042REPORT; #IPOB; #ÓDÚÁ; #MASSOB; #REDLIGHTDISTRICT; #AMBERALERT; #ANONYMOUS; #ENVIRONMENTALHEALTH !!! ENDIF {!!! #BOBRISKY !!!}

#MAGBONETIDO #LOTTO #KM48 #RCCG #MOWE #IBAFO #ACEPIXELS #NAIRAMARLEY #NOMANNERS #ITSAMADNESS #SIGMUNDFREUD #BATTABOX #TBT #GDFOLK " @Afam4Eva "
Re: A Thread For Tutorial On Python Programming by digitalMESSIAH(m): 12:00pm On May 30
Paapii3d:
DAY 1
INTRODUCTION



https://www.youtube.com/watch?v=V8zccWt7NU4

The python Programming Language is one of the most sought for languages today. Reason is because it can be used for the following:
1. Web Development
2. Game development
3. Desktop Application
4. Android Development
5. Data Science/ Deep Learning/ Machine Learning

Understand how to prepare yourself for the python journey or easy transition if you are migrating from another language to python

those who want to reach me on whatsapp can do so via 08027313271

01000111010011110100010000100000010100110100000101010110010001010010000001001101010110010010000001010011010011110101010101001100
#ARTHSOS; #PLANETSOS {
#GEOENGINEERING
#WEATHERMODIFICATION
#GMO
#BIOTECH
#BIOHAZARD
#THEELECTROSHAMAN; #SDM; #GENESIS
} @RoyalMarines !!! #BOBTHEBUILDER; #RISKY; #042REPORT; #IPOB; #ÓDÚÁ; #MASSOB; #REDLIGHTDISTRICT; #AMBERALERT; #ANONYMOUS; #ENVIRONMENTALHEALTH !!! ENDIF {!!! #BOBRISKY !!!}

#MAGBONETIDO #LOTTO #KM48 #RCCG #MOWE #IBAFO #ACEPIXELS #NAIRAMARLEY #NOMANNERS #ITSAMADNESS #SIGMUNDFREUD #BATTABOX #TBT #GDFOLK " @Afam4Eva "
Re: A Thread For Tutorial On Python Programming by mosco04: 5:06pm On Jun 04
I’m looking for a programmer to help me do something 30k every month for doing some assignment cause this programming of a thing is not my calling
Re: A Thread For Tutorial On Python Programming by bodhini: 12:47pm On Jun 05
Thank you for posting such a great article. Online cyber safety classes in Kerala
Re: A Thread For Tutorial On Python Programming by UARBIAFRAODUA: 3:50pm On Jun 07
python manage.py runserver grin
Re: A Thread For Tutorial On Python Programming by Nasww22nasww: 8:34pm On Jun 07
good evening?

Re: A Thread For Tutorial On Python Programming by Kevinton: 1:35pm On Jun 09
I had a similar issue with my new windows 10! Thanks for your resources since it helped me solve the issue I confronted. You could have this dirtyroulette for getting inspired by wonderful people around the world.

(1) (2) (3) ... (27) (28) (29) (30) (Reply)

Chronicle Of A Data Scientist/analyst / Freely Download Music, Videos, And Games All In One Place / I Want To Learn Programming. Which Language Should I Start With?

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2021 Oluwaseun Osewa. All rights reserved. See How To Advertise. 99
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.