SL LAB Mid
SL LAB Mid
CSE(AIML) –SCRIPTING LANGUAGES LAB (21CA623PE) DEPARTMENT OF CSE @ MRIET CSE(AIML) –SCRIPTING LANGUAGES LAB (21CA623PE)
1. Write a Ruby script to create a new string which is n copies of a given string where n is a non- 2. Write a Ruby script which accept the radius of a circle from the user and compute the parameter 3. Write a Ruby script which accept the user's first and last name and print them in
negative integer and area. reverse orderwith a space between them
Aim: Ruby script to create a new string which is n copies of a given string where n is a non- Aim: Ruby script which accept the radius of a circle from the user and compute the parameter and Aim: Ruby script which accept the user's first and last name and print them in reverse order with
negative integer area. a space between them
Flowchart:
Ruby Code:
def multiple_string(str, n)
return str*n
end
print multiple_string('a', 1),"\n"
print multiple_string('a', 2),"\n" Ruby Code:
print multiple_string('a', 3),"\n"
print multiple_string('a', 4),"\n" puts "Input your first name: "
print multiple_string('a', 5),"\n" fname = gets.chomp
puts "Input your last name: "
lname = gets.chomp
Ruby Code:
puts "Hello #{lname} #{fname}"
radius = 5.0
Output: perimeter = 0.0
a area = 0.0
aa print "Input the radius of the circle: "
aaa radius = gets.to_f Output:
aaaa perimeter = 2 * 3.141592653 * radius
aaaaa area = 3.141592653 * radius * radius Input your first name:
puts "The perimeter is #{perimeter}." Input your last name:
puts "The area is #{area}." Hello Naga babu
Output:
DEPARTMENT OF CSE @ MRIET CSE(AIML) –SCRIPTING LANGUAGES LAB (21CA623PE) DEPARTMENT OF CSE @ MRIET CSE(AIML) –SCRIPTING LANGUAGES LAB (21CA623PE) DEPARTMENT OF CSE @ MRIET CSE(AIML) –SCRIPTING LANGUAGES LAB (21CA623PE)
5. Write a Ruby script to find the greatest of three numbers 6. Write a Ruby script to print odd numbers from 10 to 1
4. Write a Ruby script to accept a filename from the user print the extension of that
Aim: Ruby script to find the greatest of three numbers
Flowchart:
Ruby Code:
file = "/user/system/test.rb"
# file name Ruby Code:
fbname = File.basename file
puts "File name: "+fbname x,y,z = 2,5,4
# basename if x >= y and x >= z
bname = File.basename file,".rb" puts "x = #{x} is greatest."
puts "Base name: "+bname elsif y >= z and y >= x
# file extention puts "y = #{y} is greatest." Ruby Code:
ffextn = File.extname file else
puts "Extention: "+ffextn puts "z = #{z} is greatest." puts "Odd numbers between 9 to 1: "
# path name end 9.step 1, -2 do |x|
path_name= File.dirname file puts "#{x}"
puts "Path name: "+path_name end
output Output
output:
y = 5 is greatest. Odd numbers between 9 to 1:
File name: test.rb 9
Base name: test 7
Extention: .rb 5
Path name: /user/system 3
1
DEPARTMENT OF CSE @ MRIET CSE(AIML) –SCRIPTING LANGUAGES LAB (21CA623PE) DEPARTMENT OF CSE @ MRIET CSE(AIML) –SCRIPTING LANGUAGES LAB (21CA623PE) DEPARTMENT OF CSE @ MRIET CSE(AIML) –SCRIPTING LANGUAGES LAB (21CA623PE)
7. Write a Ruby scirpt to check two integers and return true if one of them is 20 8. Write a Ruby script to check two temperatures and return true if one is less than 9. Write a Ruby script to print the elements of a given array
otherwisereturn their sum 0 andthe other is greater than 100
Aim: Ruby script to print the elements of a given array
Aim: Ruby scirpt to check two integers and return true if one of them is 20 otherwise return their Aim: Ruby script to check two temperatures and return true if one is less than 0 and the other is
sum greater than 100 Block Structure
Flowchart:
Flowchart:
Flowchart:
Ruby Code:
def makes20(x,y)
return x == 20 || y == 20 || x + y == 20
end Ruby Code:
Ruby
2.3
2017-12-28 06:01:53 +0000
10 Write a Ruby program to retrieve the total marks where subject name and marks of astudent stored in a
hash
Aim: Ruby program to retrieve the total marks where subject name and marks of a student storedin a hash
Flowchart
Ruby Code:
Output