[Solved] Python Score Counter For Controlled Test [closed]

for counter in range(0, 5): while True: try: whohost = int(input(“Who hosted the game? “)) whowins = int(input(“Who was the winner? “)) if whohost in schoolnumber and whowins in schoolnumber: break else: raise ValueError() except ValueError: print(‘Please enter a valid number from the list {}’.format(schoolnumber)) if whohost == whowins: homescores[whowins-1] += 2 else: awayscores[whowins-1] += … Read more

[Solved] Confused about this ‘lab’

Based on the description you gave, the desired output appears to be: the count (0..10000) of each number from one to six; and the average of all numbers. So you’ll probably want something like this: Number 1 occurred 1662 times. Number 2 occurred 1676 times. Number 3 occurred 1600 times. Number 4 occurred 1696 times. … Read more

[Solved] You are given an array consisting of n integers. Print the last two digits of the product of its array values [duplicate]

You can try this (it’s version of Python3): n = int(input()) arr = list(map(int, input().rstrip().split())) result = 1 for num in arr: result = (result * num) % 100 print(“{:02d}”.format(result)) A little bit modify for better algorithm: n = int(input()) arr = list(map(int, input().rstrip().split())) result = 1 for num in arr: result = (result * … Read more

[Solved] Why is my code miscalculating the total force from a list of (magnitude, angle) pairs? [closed]

from math import sqrt, sin, cos, atan2, degrees, radians def find_net_force(forces): h_force = sum( [ force[0] * cos(radians(force[1])) for force in forces ] ) v_force = sum( [ force[0] * sin(radians(force[1])) for force in forces ] ) r_force = round(sqrt((h_force ** 2) + (v_force ** 2)), 1) r_angle = round(degrees(atan2(v_force, h_force)), 1) return (r_force, r_angle) … Read more

[Solved] Shortening the following if statement?

As was mentioned by cco: if data.char in “123456789” data.board[row][col] = int(data.char) The in operator evaluates to true if it finds a variable in the specified sequence and false otherwise. It can be used for lists, strings, tuples and dictionaries. However the in will only check the keys of the dictionary – not the values. … Read more

[Solved] Python 3: How to get a random 4 digit number?

If you want to extend your solution to make sure the leading digit isn’t 0, there’s probably no super-concise way to write it; just be explicit: first = random.choice(range(1, 10)) leftover = set(range(10)) – {first} rest = random.sample(leftover, 3) digits = [first] + rest Notice that I’m taking advantage of the fact that sample takes … Read more

[Solved] higher or lower card game in python

Well, lets make your code a little more pythonic… import random DECK_SIZE = 5 # See that it generates 5 unique random number from 1 to 12 # (not including 13) thus simulating a deck of cards, # where cards cannot repeat. We add a None in the end to # indicate end of deck … Read more

[Solved] Use of . in python? [duplicate]

You use dot for 3 main reasons: Accessing members of a module: a module is simply a python file, and members can be variables, functions, classes and so on. Accessing modules within a package: a package is a directory containing a__init__ module. Some packages are nested and contain inner packages. You have to reach the … Read more

[Solved] Search and replace vulgar words in a text by using a text file containing all the bad words

i found the solution , i maked the content of the txt file in a list with split method , def check_offline(text): list_pro = open(‘full-list-bad.txt’,’r’) content = list_pro.read() list_content = content.split(‘\n’) for word in list_content : if word in text : remplacement = “*” * len(word) text = text.replace(word ,remplacement) print word print remplacement return … Read more

[Solved] Absolute beginner looking for solution

This is very simple, and is pretty much related to your understanding of the BMI’s formula. The code that suits your requirements would be the following: maxweight = (height**2/10000)*24.9 dif = round(abs(maxweight-weight),2) print(name+”, you have”,dif,”kilograms to go until you reach the maximum normal weight”) This works for both underweight and overweight values, always returning a … Read more