Answer:
Following are the code to this question:
def binarynumber(num):#defining a method binarynumber that accepts a parameter num
x=""#defining a string variable x
if (num!=0):#defining if condition to check number not equal to 0
while (num>=1):#defining a loop that check value is grater then equal to one
if (num %2==0):#defining if condition to check num is even
x=x+"0" #add string value 0 in num variable
num=num/2 #divide the value by 2
else:#defining else block
x=x+"1"#add string value 1 in num variable
num=(num-1)/2#first subtract 1 into num variable then divide the value by 2
else:
x="0"#assign string value 0 in num variable
return "".join(reversed(x))#return value
num = int (input ("Enter any number: "))#defining num variable that input the integer value
print (binarynumber(num))#using print method to call method binarynumber with passing num parameter
Output:
Enter any number: 12
1100
Explanation:
- In the above python code a method "binarynumber" is declared, in which the "num" variable passes as the parameter inside the method a string variable "x" is declared that stores all converted values.
- Inside the method and if the block is declared that checks number value is not equal to 0 if this condition is false then it will add string value and reverse its value.
- Or if the condition is true it defines a while loop that calculates the given number binary digits and returns its value.
- At the last step, the num variable is declared that inputs the integer value from the user end and calls the method by using the print method.
Answer:
#include <iostream>
using namespace std;
int main() {
int age,time;
float price;
cout<<"Enter age:";
cin>>age;
cout<<"Enter time(in 24 hour clock for noon 1200):";
cin>>time;
if(age>13){
if(time<1700){
price=5;
}else{
price=8;
}
}else{
if(time<1700){
price=2;
}else{
price=4;
}
}
cout<<"Price: $"<<price<<endl;
}
Explanation:
Okay, here are the steps to be taken in order to be able to Write a program that determines the price of a movie ticket as given in details in the question above. Therefore, checked the steps below;
==> Input the age and the time.
==> If the age is not greater than 13, input the time(that is <1700) and follow it by imputing the price.
And if the age is greater than 13, you will also need to input the price. Just as below;
#include <iostream>
using namespace std;
int main() {
int age,time;
float price;
cout<<"Enter age:";
cin>>age;
cout<<"Enter time(in 24 hour clock for noon 1200):";
cin>>time;
if(age>13){
if(time<1700){
price=5;
}else{
price=8;
}
}else{
if(time<1700){
price=2;
}else{
price=4;
}
}
cout<<"Price: $"<<price<<endl;
}
Answer:
Hi there! Please find the answer below.
Explanation:
The program below demonstrates how each of the requirements can be coded in a simple Python script. To copy the array, we can use the copy() method of the array. To calculate the diff, we can use a few different techniques, so I have implemented it using a loop over the arrays and just storing and displaying the difference in the 2 arrays.
new_string.py
def add_test_score(score):
test_score.append(score);
contact_hash = {}
test_score = []
print("Enter 5 test scores: ");
for x in range(0, 5):
input_string = input("Enter test score " + str(x + 1) + ": ")
add_test_score(int(input_string));
print(test_score);
test_score_copy = test_score.copy();
for e in test_score_copy:
if e < 60:
test_score_copy[test_score_copy.index(e)] += 10;
diff = [];
for e in test_score:
print(test_score[test_score.index(e)]);
print(test_score_copy[test_score.index(e)]);
if not test_score[test_score.index(e)] == test_score_copy[test_score.index(e)]:
diff.append(e);
print(diff);