CodeSolved

A comprehensive source of programming questions and exercises

To move the value of 2 variables

Practice Easy 18/ Download 1833 Views

Write a program that receives 2 numeric value from the input and stores in variables A and B. Then move the values ​​of these two variables (the value of variable A is to be stored within B and the value of variable B is saved within a)

10 Answers

# The numbers and the definition of variables with zero value
a = int(input("number 1 :"))
b = int(input("number 2 :"))
c = 0

# Positioning numbers and printing on output
c = a
a = b
b = c

print(a)
print(b)
Hossien Download Python
let a = parseFloat(prompt("لطفاً مقدار عددی a را وارد کنید:"));
let b = parseFloat(prompt("لطفاً مقدار عددی b را وارد کنید:"));

# Display the initial values
console.log(`مقدار اولیه a: ${a}`);
console.log(`مقدار اولیه b: ${b}`);

# Moving values
let temp = a; # Save the value A in the temporary variable
a = b;        # We attribute the amount B to A
b = temp;    # We attribute the temporary amount to b

# Displays
console.log(`مقدار جدید a: ${a}`);
console.log(`مقدار جدید b: ${b}`);
Mma123 Download JavaScript
a = int(input("please enter a number: "))
b = int(input("please enter a number: "))
print("a = ", a ,"/", "b = ", b)
a, b = b, a
print("a = ", a ,"/", "b = ", b)

It was very good and one point I got in the quadruple line that A, B "simultaneously" was used and it wouldn't be the case. User 35


Hi good time. Thank you. I am glad to help you. Alirezamoghaddam


# Get two numeric values ​​from the user
a = int(input("لطفاً مقدار عددی اول را وارد کنید: "))
b = int(input("لطفاً مقدار عددی دوم را وارد کنید: "))
# The displacement of values ​​A and b
a, b = b, a
# Displays
print("پس از جابه‌جایی:")
print("مقدار a:", a)
print("مقدار b:", b)
Milad.bio Download Python
var num1 = prompet("عدد a")
var num2 = prompet("عدد b")
var as = num1
var as2 = num2
num1 = as2
num2 = as
a = int(input("enter a number: "))
b = int(input("enter a number: "))

print("befor:")
print(f"a:{a}")
print(f"b:{b}")
a,b = b,a

print("after:")
print(f"a:{a}")
print(f"b:{b}")
User 195 Download Python
value_1 = int(input("pleas enter the number :"))    # Get the first value
value_2 = int(input("pleas enter the number :"))    # Receive a second value
value_1,value_2 = value_2,value_1                   # Displacement of the first value with the second value
print(f"value 1 : {value_1}")                       # Printing the first variable value after change
print(f"value_2 : {value_2}")                       # Printing the second variable value after change
a=int(input('a: '))
c=a
b=int(input('b: '))
print('-------------------------')
print('a= ',a)
print('b= ',b)
print('-------------------------')
a=b
b=c
print('a= ',a)
print('b= ',b)
User 35 Download Python
a = float(input("enter a:"))
b = float( input("enter b:"))
print("befor:","a=" , a , "b=",b)
print("-"*40)
a , b = b , a 
print("after:","a=" , a , "b=",b)
print("-"*40)
Ali.r.h.z Download Python
# Getting numbers from input
A =int(input("Enter Number A:"))
B =int(input("Enter Number B:"))
# Possibly
A , B =(B , A)
# Print
print("Number A:", A)
print("Number B:", B)

Submit answer

Submitting answers is currently unavailable.

Related content

Detection using AI
×
×
Close