Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Consider the code below a) Modify the code to insert another elif case so that i

ID: 1765983 • Letter: C

Question

Consider the code below

a) Modify the code to insert another elif case so that if a non-integer is entered, the output text indicates that the input value is not an integer. Show the new code

b) Modify the code to use a try-except block so that the program will try to input a value into nn and perform the if-else structure. If a non-number is entered, output the text, “Input is not a number”. Show the new code

# DiVBy3.py-Krista Hill-Feb. 4, 2018 # Example collection of functions nn = input ("Integer: ") print nn, "is non-zero and is divisible by 3'" print nn, "is zero" print nn,"is neither zero or divisible by 3" else:

Explanation / Answer

a answer:-

# collection of functions

nn = input("enter a number: ")

temp == nn

qq = nn - temp

if qq != 0

print nn, "not an integer"

elif nn!=0 and nn%3==0

print nn, "is a integer and divisible by 3"

elif nn==0

print nn, " is zero"

else:

print nn, " is neither zero or divisble by 3"

b answer:-

#include<stdio.h>

#include<stdlib.h>

int main(void){

int a;

float b,c;

printf("Enter the number ");

scanf("%f",&b);

a=b;

printf("a=%d ",a);

printf("b=%d ",b);

c=b-a;

b=b-a;

printf("a=%d ",a);

printf("b=%f ",b);

printf("c=%f ",c);

if (c==0){

printf("entered number is an interger ");

if(a==0)

printf("it is zero ");

else if(a!=0 && a%3==0)

printf("it is divisible by 3"):

else

printf("entered is non zero but not divisible by 3");

}

else

printf(" it is not an integer");

return o;

}