r/pythonhomeworkhelp • u/notevena_maester • Feb 08 '24
r/pythonhomeworkhelp • u/justspammedstuff • Jan 02 '24
How to make a contour plot of 3D points given as a CSV file
My professor gave us a CSV file full of 3D points and told us to create a contour plot. Whenever I try to to create a plot, spyder says that my z array needs to be 2D. Does anyone have any advice on how to make this work?
r/pythonhomeworkhelp • u/isosc3l3s • Dec 10 '23
Trouble converting while and for loops to functions
I am making an app that takes what info you were given about an element, and returns all the essential information. I am trying to integrate the idea into tkinter, but I cant get my loops to convert to functions, and I dont get how to change the text in the gui to display the results.
I have tried converting the loops a few times, but they dont convert.
below if my code, its still in progress
from tkinter import *
from periodicTable import elements
#RELIC
givenInfo = input("please enter an the information you were given about the element, and I will enter the info for it:") #prompt for what they were provided
#RELIC
#if else route to designate each entry of givenInfo as str, int, or float
if givenInfo.isdigit():
givenInfo = int(givenInfo)
elif givenInfo.replace('.', '', 1).isdigit():
givenInfo = float(givenInfo)
else:
givenInfo = givenInfo.capitalize()
#The proper designations for the data, for the start, it is all empty
name = ""
symbol = ""
atomNum = 0
atomMass = 0
#Loop to run through elements dictionry and make list of the values there
result = [] #List needed
for element, element_dict in elements.items(): #for (new variable made in for loop), () in (dictionary elements, but .items() designates just the values)
if (givenInfo in element_dict):
result = list(element_dict)
break
#RELIC
print(givenInfo)
#print(result)
#RELIC
#Loop to assign each value to its proper designation
i=0
while i < len(result):
if type(result[i]) is int:
atomNum = result[i]
print("The atomic number is:", atomNum)
i+=1
elif type(result[i]) is float:
atomMass = result[i]
print("The atomic mass is:", atomMass)
i+=1
elif type(result[i]) is str and len(result[i]) > 2:
name = result[i]
print("The element name:", name)
i+=1
elif type(result[i]) is str and len(result[i]) <= 2:
symbol = result[i]
print("The symbol for the element:", symbol)
i+=1
else:
print(type(result[i]))
i+=1
#______________________________________________________________Margin from main program engine______________________________________________________________#
root = Tk()
#myText=givenInfo;
firstframe = Frame(root)
firstframe.pack()
secondframe= Frame(root)
secondframe.pack( side = BOTTOM )
#Text label prompt for what user was provided in the problem label in row 0
Label(firstframe, text='What were you provded for the element?').grid(row=0)
#Result1 label in row 1
Label(firstframe, text=f"{'The symbol for the element is: '+ symbol}").grid(row=1) #this line prints the result as needed
#Result2 label in row 2
Label(firstframe, text='result2 this might be the atomic number').grid(row=2)
#Result3 label in row 3
Label(firstframe, text='result3 this might be the atomic mass').grid(row=3)
#Result4 label in row 4
Label(firstframe, text='The atomic number is:').grid(row=4)
#entry field
entry = Entry(firstframe)
#place it next to "what were you given"
entry.grid(row=0, column=1)
#answer label adjacent to label Result , so row 2 column 1
Label(firstframe,text="",textvariable=givenInfo).grid(row=2,column=1)
#creating a search button. Clicking the button should initiate the search through the dictionary.
#command attribute is for on click event.
searchButton = Button(secondframe, text ='Search')
searchButton.pack()
#creating a new button, should clear the results when clicked.
clearButton = Button(secondframe, text ='Clear')
clearButton.pack()
#creating a new window to search another element with
newWindowButton = Button(secondframe, text="New Window", command=root.mainloop)
newWindowButton.pack()
#creating a Celsius to Exit button. root.destroy will exit the window
exitbutton = Button(secondframe, text ='Exit', fg ='red', command=root.destroy)
exitbutton.pack()
root.mainloop()
the loops i am trying to convert right now are:
#Loop to assign each value to its proper designation
i=0
while i < len(result):
if type(result[i]) is int:
atomNum = result[i]
print("The atomic number is:", atomNum)
i+=1
elif type(result[i]) is float:
atomMass = result[i]
print("The atomic mass is:", atomMass)
i+=1
elif type(result[i]) is str and len(result[i]) > 2:
name = result[i]
print("The element name:", name)
i+=1
elif type(result[i]) is str and len(result[i]) <= 2:
symbol = result[i]
print("The symbol for the element:", symbol)
i+=1
else:
print(type(result[i]))
i+=1
and:
#Loop to run through elements dictionry and make list of the values there
result = [] #List needed
for element, element_dict in elements.items(): #for (new variable made in for loop), () in (dictionary elements, but .items() designates just the values)
if (givenInfo in element_dict):
result = list(element_dict)
break
i would really appreciate the help.
r/pythonhomeworkhelp • u/Off-brand-condom • Nov 16 '23
Bag of Dice project with classes
My main Problem is how Exactly my professor wants me to do the second class. From my knowledge you cant create a list within a class, I know you can make a child class but it hasn't really worked well with making dice. I just started coding a couple of months ago so this might seem simple. so any tips would be apricated.
His instructions were:
In this project, you will be creating a bag of dice that will be used in your final project.
First things first, you need to import random into your file.
Use the Die class from Programming Concepts 10. There's no need to code this again.
Normally we would import this, but for simplicity, just copy/paste the Die class here.
Your DiceBag class should contain the following members and methods.
A list of Die objects.
A singleRoll method that selects a die by its number of sides via input. If the die exists, roll it and return the result. If not, return -1.
A multiRoll method that takes a number of sides to select and number of times to roll and returns the sum of the rolls. If the selected die doesn't exist, return -1.
Once you've got both your classes present and accounted for, write some test code. Create a list of Die objects.
You should have a 4, 6, 10, 20, 50, and 100 sided die. Creat a DiceBag object containing this list of dice.
Call the singleRoll and multiRoll functions a few times and print the results to verify that it works.
The concepts 10 code is:
import random
class Die:
def __init__(self, sides):
self.sides = sides
self.value = 1
def roll(self):
self.value = random.randrange(1,self.sides+1)
return self.value
newDie = Die(20)
print(newDie.roll())
r/pythonhomeworkhelp • u/Off-brand-condom • Nov 16 '23
Bag of Dice project with classes
My main Problem is how Exactly my professor wants me to do the second class. From my knowledge you cant create a list within a class, I know you can make a child class but it hasn't really worked well with making dice. I just started coding a couple of months ago so this might seem simple. so any tips would be apricated.
His instructions were:
In this project, you will be creating a bag of dice that will be used in your final project.
First things first, you need to import random into your file.
Use the Die class from Programming Concepts 10. There's no need to code this again.
Normally we would import this, but for simplicity, just copy/paste the Die class here.
Your DiceBag class should contain the following members and methods.
A list of Die objects.
A singleRoll method that selects a die by its number of sides via input. If the die exists, roll it and return the result. If not, return -1.
A multiRoll method that takes a number of sides to select and number of times to roll and returns the sum of the rolls. If the selected die doesn't exist, return -1.
Once you've got both your classes present and accounted for, write some test code. Create a list of Die objects.
You should have a 4, 6, 10, 20, 50, and 100 sided die. Creat a DiceBag object containing this list of dice.
Call the singleRoll and multiRoll functions a few times and print the results to verify that it works.
The concepts 10 code is:
import random
class Die:
def __init__(self, sides):
self.sides = sides
self.value = 1
def roll(self):
self.value = random.randrange(1,self.sides+1)
return self.value
newDie = Die(20)
print(newDie.roll())
r/pythonhomeworkhelp • u/Redstonelight • Nov 05 '23
Need help automating ace value pick on pc's turn | Blackjack card game
I'm making a blackjack card game for my python comp.sci course and I'm almost done the game. however the system I used to allow the player to pick if the ace is valued 1 or 11, seemingly can't be modified to fit the computer's turn. I want the program to value ace at 1 if dealerScore>playerScore and 11 if dealerScore<playerScore. {P.S. Please ignore my messy code}
def AceValue():
while True:
aceInput = input('Would you like the Ace to be 1 or 11: ')
if aceInput == "1":
return 1
elif aceInput == "11":
return 11
else:
print('Please enter a valid answer (1 or 11).')Above is the AceValue function | This is how the user picks the ace value
def playerDraw():
global deck, drawnCards, play, playerScore, dealerScore, playerTurn
drawCard = random.choice(deck)
drawnCards.append(drawCard)
print(drawCard)
cardVal = drawCard[1]
if cardVal == 'A':
aceValue = AceValue()
if playerTurn:
playerScore += aceValue
else:
dealerScore += aceValue
else:
if cardVal in faceValues:
if playerTurn:
playerScore += faceValues[cardVal]
else:
dealerScore += faceValues[cardVal]
if playerTurn:
print(f"Player's score: {playerScore}")
if playerScore == 21:
print('YOU WIN!')
exit('<<Player Wins>>')
elif playerScore > 21:
print('YOU BUSTED!')
exit('<<Player Busted>>')
else:
print(f"Dealer's score: {dealerScore}")
if dealerScore == 21:
print('DEALER WINS!')
elif dealerScore > 21:
print('DEALER BUSTED!')
print('YOU WIN!')
exit('<<Dealer Busted>>')This is the draw card function | This function houses and deals with all card related tasks except for "standing".
Here is the full program if needed;
# Imported Modules
from colorama import Fore, Back, Style
from pcinput import getString
import random
# Def Functions
def AceValue():
while True:
aceInput = input('Would you like the Ace to be 1 or 11: ')
if aceInput == "1":
return 1
elif aceInput == "11":
return 11
else:
print('Please enter a valid answer (1 or 11).')
def playerDraw():
global deck, drawnCards, play, playerScore, dealerScore, playerTurn
drawCard = random.choice(deck)
drawnCards.append(drawCard)
print(drawCard)
cardVal = drawCard[1]
if cardVal == 'A':
aceValue = AceValue()
if playerTurn:
playerScore += aceValue
else:
dealerScore += aceValue
else:
if cardVal in faceValues:
if playerTurn:
playerScore += faceValues[cardVal]
else:
dealerScore += faceValues[cardVal]
if playerTurn:
print(f"Player's score: {playerScore}")
if playerScore == 21:
print('YOU WIN!')
exit('<<Player Wins>>')
elif playerScore > 21:
print('YOU BUSTED!')
exit('<<Player Busted>>')
else:
print(f"Dealer's score: {dealerScore}")
if dealerScore == 21:
print('DEALER WINS!')
elif dealerScore > 21:
print('DEALER BUSTED!')
print('YOU WIN!')
exit('<<Dealer Busted>>')
def playerStand():
global dealerTurn, playerTurn
playerTurn = False
if playerScore == 21:
print('YOU WIN!')
elif playerScore > 21:
print('YOU BUSTED!')
elif playerScore < 21:
dealerTurn = True
return
#Memory
suits = (Fore.BLACK+'\u2660'+Fore.BLACK, # Spades
Fore.BLACK+'\u2663'+Fore.BLACK, # Clubs
Fore.RED+'\u2665'+Fore.BLACK, # Hearts
Fore.RED+'\u2666'+Fore.BLACK) # Diamonds
faces = ('A', 'K','Q','J','T','9','8','7','6','5','4','3','2')
faceValues = {
'A': 1, # Ace can be 1 or 11
'K': 10,
'Q': 10,
'J': 10,
'T': 10,
'9': 9,
'8': 8,
'7': 7,
'6': 6,
'5': 5,
'4': 4,
'3': 3,
'2': 2
}
deck = []
drawCard = None
drawnCards = []
play = True
playerinput = None
dealerTurn = False
playerTurn = True
playerScore = 0
dealerScore = 0
#Process
for face in faces:
for suit in suits:
deck.append("["+face + suit+"]")
print(Fore.YELLOW)
print(Back.BLACK)
print("""\
/$$$$$$$ /$$ /$$ /$$$$$ /$$
| $$__ $| $$ | $$ |__ $$ | $$
| $$ \ $| $$ /$$$$$$ /$$$$$$| $$ /$$ | $$ /$$$$$$ /$$$$$$| $$ /$$
| $$$$$$$| $$|____ $$/$$_____| $$ /$$/ | $$|____ $$/$$_____| $$ /$$/
| $$__ $| $$ /$$$$$$| $$ | $$$$$$/ /$$ | $$ /$$$$$$| $$ | $$$$$$/
| $$ \ $| $$/$$__ $| $$ | $$_ $$ | $$ | $$/$$__ $| $$ | $$_ $$
| $$$$$$$| $| $$$$$$| $$$$$$| $$ \ $$ | $$$$$$| $$$$$$| $$$$$$| $$ \ $$
|_______/|__/_______/_______|__/ __/ ______/ _______/_______|__/ __/
""")
print(Back.GREEN)
print(Fore.BLACK)
print('')
print('''\
--- Rules ---
. The goal of blackjack is to beat the dealer (computer player) without going over 21
. Face cards are worth 10, all other cards are worth ‘face value’, except the Ace, Aces are worth 1 or 11,
whichever makes the better hand.
. Each player starts with two cards, one of the dealer’s cards is hidden until the end
. The player asks for another card by saying ‘hit’
. If the player’s card total goes over 21, the game is over. The player ‘busts’
. The player stops asking for cards by saying ‘stand’
. The dealer (computer) will hit until its cards total 16 or better
. If the dealer ‘busts’ by going over 21 the player wins automatically
''')
while play == True:
while playerTurn == True:
playerinput = getString('hit or stand: ')
if playerinput == "hit":
playerDraw()
if drawCard == 'A':
aceInput = input('Would you like the Ace to be 1 or 11: ')
if aceInput == "1":
playerScore += 1
elif aceInput == "11":
playerScore += 11
else:
print('<<Please enter a valid answer>>')
elif playerinput == "stand":
#Goto Dealer's Turn
playerStand()
elif playerinput == "a valid command":
print('ha ha, very funny')
else:
print('<<Please enter a valid command>>')
# Dealer
if dealerTurn == True:
if dealerScore > playerScore:
if dealerScore > 21:
print('DEALER BUSTED!')
elif dealerScore < 21:
print('DEALER WINS!')
dealerTurn = False
break
print('')
print("Dealer's Turn")
print('-------------')
while dealerScore < playerScore:
playerDraw()r/pythonhomeworkhelp • u/[deleted] • Aug 17 '23
A guide for beginners on how to open and read files in Python.
r/pythonhomeworkhelp • u/[deleted] • Aug 16 '23
A guide for beginners on how to open and read files in Python.
r/pythonhomeworkhelp • u/[deleted] • Aug 16 '23
What am I not seeing?!
Hi y'all.
Im still very new at this and can't seem to meet the requirements stated by my professor. Can someone please let me know what I'm missing? I keep getting the desired answer but somehow I'm not meeting the requirements posed in the question. Am I going crazy? below is the initial prompt along with my code.
4.6 Write a program to prompt the user for hours and rate per hour using input to compute gross pay. Pay should be the normal rate for hours up to 40 and time-and-a-half for the hourly rate for all hours worked above 40 hours. Put the logic to do the computation of pay in a function called computepay() and use the function to do the computation. The function should return a value. Use 45 hours and a rate of 10.50 per hour to test the program (the pay should be 498.75). You should use input to read a string and float() to convert the string to a number. Do not worry about error checking the user input unless you want to - you can assume the user types numbers properly. Do not name your variable sum or use the sum() function.
def computepay(hrs, rate):
if hrs <= 40:
pay = float(hrs * rate)
else:
normal_hours= 40
over_time= float(hrs) - float(normal_hours)
pay= float((normal_hours*rate))+ float((over_time*rate*1.5))
return pay
hrs = float(input("Enter Hours:"))
rate = float(input("Enter Rate:"))
p = computepay(hrs,rate)
print (p)
r/pythonhomeworkhelp • u/[deleted] • Aug 15 '23
Making Variables More Flexible – How to Have Users Enter Data.
r/pythonhomeworkhelp • u/[deleted] • Aug 14 '23
The Ultimate 9 Commands And Concepts in Python.
r/pythonhomeworkhelp • u/[deleted] • Aug 14 '23
The Ultimate 9 Commands And Concepts in Python.
r/pythonhomeworkhelp • u/[deleted] • Aug 12 '23
The Ultimate Guide to Python Libraries
r/pythonhomeworkhelp • u/[deleted] • Aug 12 '23
The ultimate guide to “Nested” Lists.
r/pythonhomeworkhelp • u/[deleted] • Aug 12 '23
The ultimate guide to “Nested” Lists.
r/pythonhomeworkhelp • u/[deleted] • Aug 09 '23
Simple Guide To Lists - Python.
r/pythonhomeworkhelp • u/[deleted] • Aug 09 '23
How To Install Scrapy - Windows
r/pythonhomeworkhelp • u/[deleted] • Aug 06 '23
The Ultimate Python Setup Guide for Windows
r/pythonhomeworkhelp • u/[deleted] • Aug 05 '23
A Simple Guide To For Loops - Python
r/pythonhomeworkhelp • u/[deleted] • Aug 03 '23
Python Commands: Learning the Basics Made Easy.
r/pythonhomeworkhelp • u/[deleted] • Aug 01 '23
How to write a While Loop - Python
r/pythonhomeworkhelp • u/[deleted] • Aug 01 '23
How to write a While Loop - Python
r/pythonhomeworkhelp • u/[deleted] • Aug 01 '23
How to write a While Loop - Python
r/pythonhomeworkhelp • u/[deleted] • Aug 01 '23