r/pythonhomeworkhelp • u/josephsark • Mar 08 '23
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 09 '23
How To Install Scrapy - Windows
r/pythonhomeworkhelp • u/notevena_maester • Feb 08 '24
Dictionary help. I have tried this problem every which way and have not been able to get the correct output.
r/pythonhomeworkhelp • u/[deleted] • Jul 20 '23
How to Use the “Pop” Command – Python
r/pythonhomeworkhelp • u/[deleted] • Jul 17 '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 16 '23
A guide for beginners on how to open and read files in Python.
r/pythonhomeworkhelp • u/[deleted] • Aug 12 '23
The Ultimate Guide to Python Libraries
r/pythonhomeworkhelp • u/[deleted] • Aug 01 '23
How to write a While Loop - Python
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/IntelligentInvite880 • Oct 07 '24
NEED HELP ASAPPPP
i need help creating a code on this plsssssssssssssss
r/pythonhomeworkhelp • u/[deleted] • Aug 05 '23
A Simple Guide To For Loops - Python
r/pythonhomeworkhelp • u/[deleted] • Jul 16 '23
Ultimate Guide To Dictionaries In Python
r/pythonhomeworkhelp • u/[deleted] • Aug 01 '23
How to write a While Loop - Python
r/pythonhomeworkhelp • u/[deleted] • Jul 17 '23
How To Install Scrapy - Windows
r/pythonhomeworkhelp • u/Chance_Ad7603 • Feb 28 '22
Need help with python code, instructions attached and the code I have
r/pythonhomeworkhelp • u/Plane-Currency-777 • Apr 07 '22
Reversing the ends of a 4 digit number with no strings, modules or libraries (i'm new)
Given a four digit positive integer number with nonzero digits, write a Python functions named
get_reversed_endsto return the integer number created by putting the two end digits in reverse order. For example, for the given number, 4325,
get_reversed_ends(4325)must return 54 because when we extract the digits 5 and 4 and put them together we can form 54. You are not allowed to use math module or any string operations or any other Python library or module here.
and this is the code I wrote out (yes, I know it's wrong) but this extracts the digits, right? Now I just need to put the first and last digit and reverse them.
def get_reversed_ends(a_number):
"""Return integer number created by putting the two end digits in reverse order"""
a_number =(a_number % 10)
return a_number
a_number =(a_number // 10)
return a_number
a_number = (a_number % 10)
return a_number
a_number = (a_number // 10)
return a_number
a_number = (a_number % 10)
return a_number
a_number = (a_number // 10)
return a_number
a_number = (a_number // 10)
return a_number
def main()
a_number = 2549
print(get_reversed_ends(a_number))
a_number = 7578
print(get_reversed_ends(a_number))
if __name__ == "__main__":
main()r/pythonhomeworkhelp • u/Shojoe_ • May 04 '22
Help plz does anyone know hot to do this
r/pythonhomeworkhelp • u/Old-Two-2825 • Jan 20 '22
Intro Python assistance please!
Hi everyone,
I am having difficulty correcting the syntax error in my code below. I am specifically having difficulties with the last two lines of the code it seems. Ideas on how to correct my code? Any help of any kind would be helpful, even an explanation, I am in my first comp sci class in uni this semester! Question wanted output: "Enter integer: 4
You entered: 4
4 squared is 16
And 4 cubed is 64 !!
Enter another integer: 5 4 + 5 is 9
4 * 5 is 20"
My code:
user_num = int(input('Enter integer:\n'))
print('You entered', user_num)
print(user_num, 'squared is', user_num*user_num)
print('And', user_num, 'cubed is', user_num*user_num*user_num, '!!')
user_num2 = int(input('Enter another integer: /n')
print(str(user_num), '+', str(user_num2), "is", user_num + user_num2)
print(str(user_num), '*' ,str(user_num2), "is", user_num * user_num2)