Python code.. Nine coins are placed in a 3x3 matrix with some face up and some face down. You can represent the state of the coins with the values 0 and 1.
000
010
000
etc.
Each state can also be represented using a binary number. For example, the preceding matrices correspond to the numbers: 000010000 There are a total of 512 possibilites. So, you can use the decimal numbers 0,1,2,3 etc., and 511 to represent all states of the matrix. Write a program that prompts the user to enter a number between 0 and 511 and displays the corresponding 3x3 matrix with the character H and T. 0 represents H and 1 represents T.
def decimaltobinary(number):
binary = ""
while (number >= 1):
number, remainder = divmod(number, 2)
binary = binary + str(remainder)
return binary
def main():
number = eval(input("Enter a number between 0 and 511: "))
binary = decimaltobinary(number)
binary = list(binary.zfill(9))
binary = list(map(int, binary))
final_list = ['T' if x == 1 else 'H' for x in binary]
for i in range(3):
print(" ".join(final_list[i*3:(i+1)*3]))
main()
num = str(bin(int(input("Enter a number between 0 and 511: "))).replace("0b", "")) #Converting user input number to binary and then to string fill = 9 - len(num) for i in range(1, fill+1): #Filling leading zeroes of binary with H in matrix if(i%3 == 0): print("H") else: print("H", end=" ") for i in range(1, len(num)+1): #Filling rest matrix with corresponding H or T if((fill+i)%3 == 0): if num[i-1] == '0': print("H") else: print("T") elif num[i-1] == '0': print("H", end=" ") else: print("T", end=" ")
Python code.. Nine coins are placed in a 3x3 matrix with some face up and some...
Can you modify this code so that it display the number of coins and subtotal for each type of coin(dimes, penny, quarter, nickel) and the total value in the wallet. But still reads the data from file coins.txt. Which is below MyCode. The original question was this: Two classes are given: Coin and Wallet. Write an application named MyWallet.java that reads all coins from a data file named coins.txt. The first line in the data file contains the number of...
how
to make my code of python work probely
my q is how to write a code to find the average actual water
level, average error by using python
and my program should be flexible where user can select the
column no. If you can see in the main program, it asked which
column to know the maximum or average, the column number is passed
to the function. The function should look which column to do.
#THIS PROGRAMMING IS ABLE...
Can you please enter this python program code into an IPO Chart? import random def menu(): print("\n\n1. You guess the number\n2. You type a number and see if the computer can guess it\n3. Exit") while True: #using try-except for the choice will handle the non-numbers #if user enters letters, then except will show the message, Numbers only! try: c=int(input("Enter your choice: ")) if(c>=1 and c<=3): return c else: print("Enter number between 1 and 3 inclusive.") except: #print exception print("Numbers Only!")...
Can you add code comments where required throughout this Python Program, Guess My Number Program, and describe this program as if you were presenting it to the class. What it does and everything step by step. import random def menu(): #function for getting the user input on what he wants to do print("\n\n1. You guess the number\n2. You type a number and see if the computer can guess it\n3. Exit") while True: #using try-except for the choice will handle the...
IN PYTHON! Radix Conversion(*UP TO BASE 37*) Constraints: • Use only basic arithmetic and comparison operations. Do not make any function calls other than the recursive call to convertBase Write a recursive function: convertBase(n,base) that will convert the non-negative decimal number n (type integer) to the specified base and return it as a string. Note that decimal values can be converted to a different number base by repeatedly dividing the residual quotient of n // base until it is zero,...
Wondering if I could get some guidance on setting up
newMatrix(). Language is C
Matrix ADT Specifications In addition to the main program Sparse.c and the altered List.c from pal, you will implement a Matrix ADT in a file called Matrix.c. This ADT will contain a private inner struct (similar to Node in your List ADT) encapsulating the column and value information corresponding to a matrix entry. You can give this inner struct any name you wish, but I will...
Undecimal to decimal&decimal to undecimal
#Your code here
Thank you!
Binary-to-Decimal In a previous lab, we considered converting a byte string to decimal. What about converting a binary string of arbitrary length to decimal? Given a binary string of an arbitrarily length k, bk-1....bi .box the decimal number can be computed by the formula 20 .bo +21.b, + ... + 2k-1. bx-1- In mathematics, we use the summation notation to write the above formula: k- 2.b; i=0) In a program,...
Python has the complex class for performing complex number arithmetic. For this assignment, you will design and implement your own Complex class. Note that the complex class in Python is named in lowercase, while our custom Complex class is named with C in uppercase. A complex number is of the form a + bi, where a and b are real numbers and i is √-1. The numbers a and b are known as the real part and the imaginary part...
I haven't code in awhile and would like some help getting back
on my feet. Need to code this in C++. Thank you!
In this homework, you will implement a simple version of the game Battleship, in which the player tries to destroy ships hidden on a map using a system of coordinates. In this program, the map will be represented by a 4x4 matrix of integers. A 1 in the matrix represents the presence of a ship. There are...
PYTHON The provided code in the ATM program is incomplete. Complete the run method of the ATM class. The program should display a message that the police will be called after a user has had three successive failures. The program should also shut down the bank when this happens. [comment]: <> (The ATM program allows a user an indefinite number of attempts to log in. Fix the program so that it displays a message that the police will be called...