Python Forum
Conceptualizing modulus. How to compare & communicate with values in a Dictionary
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Conceptualizing modulus. How to compare & communicate with values in a Dictionary
#1
Hello all

I have two questions

The first is why one change calculator works and the other doesn't.

The second question is about how to efficiently communicate and compare dictionary values while citing who they belong to.

Starting with the first you have two change calculator programs

Program A this functions

currency=float(input("enter value in $- "))
currency=currency*100
dollar=int(currency/100)
print("dollar-",dollar)
ra=currency%100
#print(ra)
quarters=int(ra/25)
print("quarters-",quarters)
ra=int(ra%25)
#print(ra))
dimes=int(ra/10)
print("dime-",dimes)
ra=int(ra%10)
#print(ra)
nickel=int(ra/5)
print("nickel-",nickel)
ra=int(ra%5)
#print(ra)
penny=int(ra/1)
print("penny-",penny)
Program B this partially functions
dollar=1
quarter=.25
dime=.10
nickel=.05
penny=.01
total=float(input("Enter the total amount: "))
print("The total can be reduced to")
print (int(total/dollar),"Dollars") #Amount of dollars
total = total%dollar
print (int(total/quarter),"Quarters") #Amount of quarters
total = total%quarter
print (int(total/dime),"Dimes") #Amount of dimes
total = total%dime
print (int(total/nickel),"Nickel") #Amount of nickel
total = total%nickel
print (int(total/penny),"Pennies") #Amount of pennies
I'm looking for a simple solution to fix the second program. I think the flaw is related to how I was programming blind with the mod operator. Modding a smaller number against a larger one like in this example
https://visualfractions.com/calculator/m...s-3-mod-5/
Where 3 mod 5 is 3 is over my head logic for now. I could probably watch a video and understand how it works so this isn't really my question but I think its related to my ignorance. What I'm really asking is why does the first program work and not the second and if there a simple way to fix the second program or am I chasing a waterfall trying to use that method?


The second question is a little simpler to ask.

I'm trying to count NPCs in a dictionary and compare their values while citing who they are. So far I have the count right but comparing the values and citing who they belong too has been a Sick Sick .


dictStudents={'001':['Grex','22','40'], '002':['C-Paul','02' ,'88'], '003':['Aquille','11','76']}  
dictionary_length = len(dictStudents)
print('The school has:',dictionary_length,'students.')

maximum = max(dictStudents[2], key=dictStudents[2].get) 
print(maximum, dictStudents[2][maximum])
___
These are total personality and ability scores next to names.

How would I print that C-Paul has the highest ability score with 88 or that Grex has the highest personality score with 22? I have found ways where I can identify the max of all values. I'm trying to compare specific values and identify the person who has it. I'm also wondering if I can name the values and reference the values by whatever variable or name so its ['Name','personality' ,'ability']?
buran write Feb-25-2021, 07:17 PM:
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.
Reply


Messages In This Thread
Conceptualizing modulus. How to compare & communicate with values in a Dictionary - by Kaanyrvhok - Feb-25-2021, 07:10 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question Using Lists as Dictionary Values bfallert 8 276 Apr-21-2024, 06:55 AM
Last Post: Pedroski55
  How to communicate between Electron Framework and python Abdul_Rafey 0 226 Mar-09-2024, 12:18 PM
Last Post: Abdul_Rafey
  cmath.rect accepts a negative modulus JMB 2 335 Jan-17-2024, 08:00 PM
Last Post: JMB
  need to compare 2 values in a nested dictionary jss 2 863 Nov-30-2023, 03:17 PM
Last Post: Pedroski55
  Loop through values and compare edroche3rd 6 688 Oct-18-2023, 04:04 PM
Last Post: edroche3rd
  Trying to compare string values in an if statement israelsattleen 1 554 Jul-08-2023, 03:49 PM
Last Post: deanhystad
  Printing specific values out from a dictionary mcoliver88 6 1,393 Apr-12-2023, 08:10 PM
Last Post: deanhystad
  Compare variable with values in a file paulo79 1 1,111 Apr-22-2022, 03:16 AM
Last Post: Pedroski55
Question How to print each possible permutation in a dictionary that has arrays as values? noahverner1995 2 1,744 Dec-27-2021, 03:43 AM
Last Post: noahverner1995
  Getting values from a dictionary brunolelli 5 3,579 Mar-31-2021, 11:57 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020