برنامه نویسی زبان سی شارپ
برنامه ای بنویسید که نام کاربری و رمز عبور را از کاربر دریافت نماید و در صورت صحیح بودن، سه عدد از ورودی بگیرد لطفا حلش کنید ممنون
2 پاسخ
سلام این کد برای پایتونه، تغریبا همون کار رو انجام میده و یه چیز اضافه هم داره مثلا اعدادی که دریافت شده رو با هم جمع و در آخر به توان 2 میرسونه
ممکنه به دردت بخوره
#correct username and password
correct_username = "a"
correct_password = "1"
#input username and password
username = input("Please enter your username : ")
password = input("Please enter Your password: ")
#sum input numbers
sum_number = 0
#list of input numbers
list_of_numbers = []
if (username == correct_username, password == correct_password):
#reapet the loop 3 time
for num in range(1,4):
# input number and save to list
numbers = int(input(f"please enter your Num {num} :"))
list_of_numbers.append(numbers)
# sum of input numbers
sum_number += numbers
# print sum of numbers and exponent
print(f"your sum of numbers is: {sum_number ** 2}")
# print list of numbers
print(list_of_numbers)
using System;
class Program
{
static void Main(string[] args)
{
// Define correct username and password
string correctUsername = "username";
string correctPassword = "password";
// Prompt user for username
Console.Write("Enter username: ");
string username = Console.ReadLine();
// Prompt user for password
Console.Write("Enter password: ");
string password = Console.ReadLine();
// Check if username and password are correct
if (username == correctUsername && password == correctPassword)
{
Console.WriteLine("Login successful!");
// Prompt user for three numbers
Console.Write("Enter number 1: ");
int num1 = int.Parse(Console.ReadLine());
Console.Write("Enter number 2: ");
int num2 = int.Parse(Console.ReadLine());
Console.Write("Enter number 3: ");
int num3 = int.Parse(Console.ReadLine()); }
else
{
Console.WriteLine("Invalid username or password.");
}
// Wait for user input before closing console window
Console.ReadLine();
}
}