Write a program to take input of name, rollno and marks obtained by a student in 4 subjects of 100 marks each and display the name, rollno with percentage score secured in python programming
Answers
Answer: Java Program for this question
Explanation:
Hey man, I know how to do this on Java but not on phython :/
Maybe it will help you ->
I have given two java codes, 1st one using functions and 2nd without functions. The program accepts name, age, roll no, marks and calulates average percentage as well as maximum marks
This is done using functions in java-
import java.util.Scanner;
public class Student
{
String name;
int age, m1, m2, m3, max, rollno;
double avg;
Student (String n, int a, int eng, int maths, int comp, int no)
{
//this is a constructor to assign values, it is not compulsory
name=n;
age=a;
m1=eng;
m2=maths;
m3=comp;
max=100;
avg=0.0;
rollno=no;
}
void accept ()
{
Scanner sc = new Scanner (System.in);
System.out.println ("Enter your name");
name = sc.nextLine();
System.out.println("Enter your age");
age=sc.nextInt();
System.out.println("Enter rollno");
rollno =sc.nextInt();
System.out.println ("Enter Biology Marks");
m1 = sc.nextInt();
System.out.println ("Enter Maths Marks");
m2 = sc.nextInt();
System.out.println ("Enter English Marks");
m3 = sc.nextInt();
}
void compute ()
{
max = Math.max(m1,Math.max(m2,m3));
avg = (m1+m2+m3)/3.0;
}
void display ()
{ System.out.println ("The name is "+name);
System.out.println("The age is "+age);
System.out.println("The roll no is "+rollno);
System.out.println("The marks in three subjects are "+m1+" "+m2+" "+m3);
System.out.println("The Average Marks are "+avg);
System.out.println("The Maximum Marks are "+max);
}
public static void main ()
{
Student ob = new Student("Student Name", 16, 90, 70, 70, 14);
ob.accept();
ob.compute();
ob.display();
}
}
You can do the same code without functions -
import java.util.Scanner;
public class StudentMarks
{
public static void main ()
{
Scanner sc = new Scanner (System.in);
System.out.println ("Enter your name");
String name = sc.nextLine();
System.out.println("Enter your age");
int age=sc.nextInt();
System.out.println("Enter roll number");
int rollno = sc.nextInt();
System.out.println ("Enter Biology Marks");
int m1 = sc.nextInt();
System.out.println ("Enter Maths Marks");
int m2 = sc.nextInt();
System.out.println ("Enter English Marks");
int m3 = sc.nextInt();
double max = Math.max(m1,Math.max(m2,m3));
double avg = (m1+m2+m3)/3.0;
System.out.println ("The name is "+name);
System.out.println("The age is "+age);
System.out.println("The roll no is "+rollno);
System.out.println("The marks in three subjects are "+m1+" "+m2+" "+m3);
System.out.println("The Average Marks are "+avg);
System.out.println("The Maximum Marks are "+max);
}
}